-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_collection.py
59 lines (52 loc) · 2.96 KB
/
create_collection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import sys
def create_folders_and_files(base_dir, name, files_headers):
"""
Create folders and files with headers for a specific project component.
"""
dir_path = os.path.join(base_dir, name)
os.makedirs(dir_path, exist_ok=True)
for file_name, headers in files_headers.items():
file_path = os.path.join(dir_path, file_name)
try:
with open(file_path, 'w') as file:
file.write(headers + "\n")
except IOError as e:
return f"Error writing to {file_path}: {e}"
def create_project_structure(name):
files_structure = {
"./collection": {
"endpoint.csv": "endpoint,endpoint-url,parameters,plugin,entry-date,start-date,end-date",
"source.csv": "source,attribution,collection,documentation-url,endpoint,licence,organisation,pipelines,entry-date,start-date,end-date",
"old-resource.csv": "old-resource,status,resource,notes"
},
"./pipeline": {
"column.csv": "column,dataset,end-date,endpoint,entry-date,field,resource,start-date",
"combine.csv": "dataset,end-date,endpoint,entry-date,field,resource,separator,start-date",
"concat.csv": "end-date,entry-date,endpoint,field,fields,dataset,resource,separator,start-date",
"convert.csv": "end-date,endpoint,entry-date,parameters,dataset,plugin,resource,start-date",
"default-value.csv": "dataset,end-date,endpoint,entry-date,entry-number,field,resource,start-date,value",
"default.csv": "dataset,default-field,end-date,endpoint,entry-date,entry-number,field,resource,start-date",
"entity-organisation.csv":"dataset,entity-minimum,entity-maximum,organisation",
"expect.csv":"datasets,organisations,operation,parameters,name,description,notes,severity,responsibility,end-date,entry-date,start,date",
"filter.csv": "dataset,end-date,endpoint,entry-date,entry-number,field,pattern,resource,start-date",
"lookup.csv": "prefix,resource,entry-number,organisation,reference,entity",
"old-entity.csv" : "old-entity,status,entity,notes,end-date,entry-date,start-date",
"patch.csv": "dataset,end-date,endpoint,entry-date,entry-number,field,pattern,resource,start-date,value",
"skip.csv": "dataset,end-date,endpoint,entry-date,entry-number,pattern,resource,start-date",
"transform.csv": "dataset,end-date,endpoint,entry-date,entry-number,field,replacement-field,resource,start-date"
}
}
for base_dir, headers in files_structure.items():
result = create_folders_and_files(base_dir, name, headers)
if result:
return result
return f"Created folders and files for '{name}' successfully."
def main(project_name):
result = create_project_structure(project_name)
print(result)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <project_name>")
else:
main(sys.argv[1])