1
1
import argparse
2
+ import copy
2
3
import os
3
4
import re
4
5
import sys
7
8
8
9
from .. import RDFWriter
9
10
from . import VersionConverter
10
- from ..utils import ConversionFormats
11
+ from ..parser_utils import RDF_CONVERSION_FORMATS
11
12
12
13
try :
13
14
unicode = unicode
14
15
except NameError :
15
16
unicode = str
16
17
17
18
19
+ CONVERSION_FORMATS = copy .deepcopy (RDF_CONVERSION_FORMATS )
20
+ CONVERSION_FORMATS .update ({
21
+ 'v1_1' : '.xml' ,
22
+ 'odml' : '.odml'
23
+ })
24
+
25
+
18
26
class FormatConverter (object ):
19
27
20
28
@classmethod
@@ -35,7 +43,7 @@ def convert(cls, args=None):
35
43
"""
36
44
parser = argparse .ArgumentParser (description = "Convert directory with odml files to another format" )
37
45
parser .add_argument ("input_dir" , help = "Path to input directory" )
38
- parser .add_argument ("result_format" , choices = list (ConversionFormats ),
46
+ parser .add_argument ("result_format" , choices = list (CONVERSION_FORMATS ),
39
47
help = "Format of output files" )
40
48
parser .add_argument ("-out" , "--output_dir" , help = "Path for output directory" )
41
49
parser .add_argument ("-r" , "--recursive" , action = "store_true" ,
@@ -55,11 +63,11 @@ def convert_dir(cls, input_dir, output_dir, parse_subdirs, res_format):
55
63
Possible choices: "v1_1" (converts to version 1.1 from version 1 xml)
56
64
"odml" (converts to .odml from version 1.1 .xml files)
57
65
"turtle", "nt" etc. (converts to rdf formats from version 1.1 .odml files)
58
- (see full list of rdf serializers in utils.ConversionFormats )
66
+ (see full list of rdf serializers in CONVERSION_FORMATS )
59
67
"""
60
- if res_format not in ConversionFormats :
68
+ if res_format not in CONVERSION_FORMATS :
61
69
raise ValueError ("Format for output files is incorrect. "
62
- "Please choose from the list: {}" .format (list (ConversionFormats )))
70
+ "Please choose from the list: {}" .format (list (CONVERSION_FORMATS )))
63
71
64
72
cls ._check_input_output_directory (input_dir , output_dir )
65
73
input_dir = os .path .join (input_dir , '' )
@@ -99,14 +107,14 @@ def _convert_file(cls, input_path, output_path, res_format):
99
107
p , _ = os .path .splitext (output_path )
100
108
output_path = p + ".odml"
101
109
odml .save (odml .load (input_path ), output_path )
102
- elif res_format in ConversionFormats :
103
- if not output_path .endswith (ConversionFormats [res_format ]):
110
+ elif res_format in CONVERSION_FORMATS :
111
+ if not output_path .endswith (CONVERSION_FORMATS [res_format ]):
104
112
p , _ = os .path .splitext (output_path )
105
- output_path = p + ConversionFormats [res_format ]
113
+ output_path = p + CONVERSION_FORMATS [res_format ]
106
114
RDFWriter (odml .load (input_path )).write_file (output_path , res_format )
107
115
else :
108
116
raise ValueError ("Format for output files is incorrect. "
109
- "Please choose from the list: {}" .format (list (ConversionFormats )))
117
+ "Please choose from the list: {}" .format (list (CONVERSION_FORMATS )))
110
118
111
119
@staticmethod
112
120
def _create_sub_directory (dir_path ):
0 commit comments