-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapitainizer.py
executable file
·75 lines (67 loc) · 3.04 KB
/
capitainizer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import click
from capitainizer.position import PositionThese
from capitainizer.capitainizer_whitout_metadata import Capitainizer_files
#SRC_DIR, cli en arguement
SRC_PATH="../encpos/data"
#Publication_package_dir ou Result_package
DEST_PATH="./data"
#Argument optionnel et discuter
METADATA = '../encpos/data/encpos.tsv'
#transformer ça en cli avec des possibilités de faire un dossier, l'intégral ou rien du tout
@click.command()
@click.argument('input', type=str)
@click.argument('output', type=str)
@click.argument('template', type=str)
@click.option('--metadata', type=str, help='Enter the metadata files of the XML files')
def main(input, output, template, metadata):
"""
INPUT: Enter the name of the folder who contains the XML files or the differents folders who contains the XML files
OUTPUT: Enter the destination path
TEMPLATE: Enter the template xml for the collections entry
"""
if input is not None:
SRC_PATH = input
if metadata is not None :
METADATA = metadata
if output is not None :
DEST_PATH = output
if template is not None:
template_collection = template
if not os.path.isdir(DEST_PATH):
os.makedirs(DEST_PATH)
list_file_or_dir = sorted(os.listdir(SRC_PATH))
list_dir = []
for name_dir in list_file_or_dir:
if os.path.isdir(os.path.join(SRC_PATH, name_dir)):
#Ajouter le nom des dossiers que vous ne souhaitez pas capitanizer
list_dir.append(name_dir)
folder_name = None
if metadata is not None :
pt = PositionThese(SRC_PATH, METADATA, template_collection, 'templates/__capitains_work_encpos.xml', 'templates/edition.xml', 'templates/refs_decl.xml', 'templates/Add_EncodingDesc.xsl')
pt.write_textgroup(folder_name, DEST_PATH, list_dir)
else:
cpt = Capitainizer_files(SRC_PATH, template_collection, 'templates/__capitains_work.xml', 'templates/edition.xml', 'templates/refs_decl.xml', 'templates/Add_EncodingDesc.xsl')
cpt.write_textgroup(folder_name, DEST_PATH, list_dir)
list_dir = []
for root, dirs, files in os.walk(SRC_PATH):
for file in files:
if "xml" in file:
if root not in list_dir:
list_dir.append(root)
for root_folder in list_dir:
#évite d'intégrer les dossiers ou fichiers
folder_name = root_folder.split("/")[-1]
#list_works contient tous le fichiers à capitainiser
list_works = [f for f in os.listdir("{0}".format(root_folder)) if "xml" in f]
if metadata is not None :
year = folder_name.split("_")[-1]
if pt.write_textgroup(year, DEST_PATH, list_works):
if pt.write_work(folder_name, year, DEST_PATH):
pt.write_edition(folder_name, DEST_PATH)
else:
if cpt.write_textgroup(folder_name, DEST_PATH, list_works):
if cpt.write_work(folder_name, DEST_PATH, list_works):
cpt.write_edition(folder_name, DEST_PATH, list_works)
if __name__ == "__main__":
main()