@@ -47,42 +47,44 @@ class Extractor:
4747 # binary blobs too. So we overwrite all the default newline, delimiter,
4848 # and quotation characters with strings which are almost guaranteed
4949 # to never come up in an ESRI style blob ;)
50- __NEWLINE = b'arcgissuxxxxxxxxxx'
51- __DELIMITER = b'reallynooneneedstopayourexorbitantlicensingfeesjustembracethefossinstead'
52- __QUOTE = b'qgisisthebestweallknowthat'
53-
54- COLORS = 'Colors'
55- FILL_SYMBOLS = 'Fill symbols'
56- LINE_SYMBOLS = 'Line symbols'
57- MARKER_SYMBOLS = 'Marker symbols'
58- COLOR_RAMPS = 'Color ramps'
59- LABELS = 'Labels'
60- MAPLEX_LABELS = 'Maplex Labels'
61- AREA_PATCHES = 'Area Patches'
62- LINE_PATCHES = 'Line Patches'
63- SCALE_BARS = 'Scale Bars'
64- LEGEND_ITEMS = 'Legend Items'
65- SCALE_TEXTS = 'Scale Texts'
66- BORDERS = 'Borders'
67- BACKGROUNDS = 'Backgrounds'
68- TEXT_SYMBOLS = 'Text Symbols'
69- NORTH_ARROWS = 'North Arrows'
70- SHADOWS = 'Shadows'
71-
72- NAME = 'NAME'
73- TAGS = 'TAGS'
74- CATEGORY = 'CATEGORY'
75- ID = 'ID'
76- BLOB = 'BLOB'
77-
78- MDB_EXPORT_BINARY = 'mdb-export'
50+ __NEWLINE = b"arcgissuxxxxxxxxxx"
51+ __DELIMITER = (
52+ b"reallynooneneedstopayourexorbitantlicensingfeesjustembracethefossinstead"
53+ )
54+ __QUOTE = b"qgisisthebestweallknowthat"
55+
56+ COLORS = "Colors"
57+ FILL_SYMBOLS = "Fill symbols"
58+ LINE_SYMBOLS = "Line symbols"
59+ MARKER_SYMBOLS = "Marker symbols"
60+ COLOR_RAMPS = "Color ramps"
61+ LABELS = "Labels"
62+ MAPLEX_LABELS = "Maplex Labels"
63+ AREA_PATCHES = "Area Patches"
64+ LINE_PATCHES = "Line Patches"
65+ SCALE_BARS = "Scale Bars"
66+ LEGEND_ITEMS = "Legend Items"
67+ SCALE_TEXTS = "Scale Texts"
68+ BORDERS = "Borders"
69+ BACKGROUNDS = "Backgrounds"
70+ TEXT_SYMBOLS = "Text Symbols"
71+ NORTH_ARROWS = "North Arrows"
72+ SHADOWS = "Shadows"
73+
74+ NAME = "NAME"
75+ TAGS = "TAGS"
76+ CATEGORY = "CATEGORY"
77+ ID = "ID"
78+ BLOB = "BLOB"
79+
80+ MDB_EXPORT_BINARY = "mdb-export"
7981
8082 @staticmethod
8183 def is_windows () -> bool :
8284 """
8385 Returns True if the plugin is running on Windows
8486 """
85- return os .name == 'nt'
87+ return os .name == "nt"
8688
8789 @staticmethod
8890 def get_process_startup_info ():
@@ -112,9 +114,9 @@ def get_process_keywords():
112114 """
113115 kw = {}
114116 if Extractor .is_windows ():
115- kw [' startupinfo' ] = Extractor .get_process_startup_info ()
117+ kw [" startupinfo" ] = Extractor .get_process_startup_info ()
116118 if sys .version_info >= (3 , 6 ):
117- kw [' encoding' ] = "cp{}" .format (Extractor .get_windows_code_page ())
119+ kw [" encoding" ] = "cp{}" .format (Extractor .get_windows_code_page ())
118120 return kw
119121
120122 @staticmethod
@@ -124,11 +126,11 @@ def get_mdb_tools_binary_path(executable: str) -> str:
124126 :param executable: mdb tools executable name
125127 :return: path for executable
126128 """
127- mdbtools_path = QSettings ().value (' /plugins/slyr/mdbtools_path' )
129+ mdbtools_path = QSettings ().value (" /plugins/slyr/mdbtools_path" )
128130 if mdbtools_path :
129131 return os .path .join (mdbtools_path , executable )
130132 elif Extractor .is_windows ():
131- return os .path .join (os .path .dirname (__file__ ), ' bin' , executable )
133+ return os .path .join (os .path .dirname (__file__ ), " bin" , executable )
132134 return executable
133135
134136 @staticmethod
@@ -140,14 +142,16 @@ def is_mdb_tools_binary_available() -> bool:
140142
141143 command = [Extractor .get_mdb_tools_binary_path (Extractor .MDB_EXPORT_BINARY )]
142144 try :
143- with subprocess .Popen (command ,
144- stdout = subprocess .PIPE ,
145- stdin = subprocess .DEVNULL ,
146- stderr = subprocess .STDOUT ,
147- universal_newlines = True ,
148- ** Extractor .get_process_keywords ()) as proc :
145+ with subprocess .Popen (
146+ command ,
147+ stdout = subprocess .PIPE ,
148+ stdin = subprocess .DEVNULL ,
149+ stderr = subprocess .STDOUT ,
150+ universal_newlines = True ,
151+ ** Extractor .get_process_keywords (),
152+ ) as proc :
149153 for line in proc .stdout :
150- if ' row-delimiter' in line :
154+ if " row-delimiter" in line :
151155 return True
152156 except FileNotFoundError :
153157 pass
@@ -159,10 +163,10 @@ def _remove_quote(val):
159163 """
160164 Removes the custom quotation character from start/end of values
161165 """
162- if val [:len (Extractor .__QUOTE )] == Extractor .__QUOTE :
163- val = val [len (Extractor .__QUOTE ):]
164- if val [- len (Extractor .__QUOTE ):] == Extractor .__QUOTE :
165- val = val [:- len (Extractor .__QUOTE )]
166+ if val [: len (Extractor .__QUOTE )] == Extractor .__QUOTE :
167+ val = val [len (Extractor .__QUOTE ) :]
168+ if val [- len (Extractor .__QUOTE ) :] == Extractor .__QUOTE :
169+ val = val [: - len (Extractor .__QUOTE )]
166170 return val
167171
168172 @staticmethod
@@ -174,9 +178,9 @@ def _extract_text(val):
174178 """
175179 val = Extractor ._remove_quote (val )
176180 try :
177- val = val .decode (' UTF-8' )
181+ val = val .decode (" UTF-8" )
178182 except UnicodeDecodeError :
179- val = val .decode (' latin-1' )
183+ val = val .decode (" latin-1" )
180184 return val
181185
182186 @staticmethod
@@ -185,7 +189,7 @@ def _format_value(val):
185189 Tries to convert a string value to a nicer type
186190 """
187191 val = Extractor ._extract_text (val )
188- if val == '' :
192+ if val == "" :
189193 return None
190194
191195 try :
@@ -206,7 +210,11 @@ def extract_non_spatial_table_from_mdb(file_path: str, table_name: str):
206210 :param table_name: table name to extract
207211 :return: list of row values (first line is header)
208212 """
209- raise RequiresLicenseException ('Converting {} document requires a licensed version of SLYR' .format (file_path ))
213+ raise RequiresLicenseException (
214+ "Converting {} document requires a licensed version of SLYR" .format (
215+ file_path
216+ )
217+ )
210218
211219 @staticmethod
212220 def extract_styles (file_path : str , symbol_type : str ): # pylint: disable=too-many-locals,too-many-branches,too-many-statements
@@ -218,22 +226,27 @@ def extract_styles(file_path: str, symbol_type: str): # pylint: disable=too-man
218226 """
219227 binary = Extractor .get_mdb_tools_binary_path (Extractor .MDB_EXPORT_BINARY )
220228
221- export_args = [binary ,
222- '-q' ,
223- '{}' .format (Extractor .__QUOTE .decode ('ASCII' )),
224- '-R' ,
225- '{}' .format (Extractor .__NEWLINE .decode ('ASCII' )),
226- '-d' ,
227- '{}' .format (Extractor .__DELIMITER .decode ('ASCII' )),
228- '-b' ,
229- 'raw' ,
230- file_path ,
231- symbol_type ]
229+ export_args = [
230+ binary ,
231+ "-q" ,
232+ "{}" .format (Extractor .__QUOTE .decode ("ASCII" )),
233+ "-R" ,
234+ "{}" .format (Extractor .__NEWLINE .decode ("ASCII" )),
235+ "-d" ,
236+ "{}" .format (Extractor .__DELIMITER .decode ("ASCII" )),
237+ "-b" ,
238+ "raw" ,
239+ file_path ,
240+ symbol_type ,
241+ ]
232242
233243 CREATE_NO_WINDOW = 0x08000000
234244 try :
235- result = subprocess .run (export_args , stdout = subprocess .PIPE , # pylint: disable=subprocess-run-check
236- creationflags = CREATE_NO_WINDOW )
245+ result = subprocess .run (
246+ export_args ,
247+ stdout = subprocess .PIPE , # pylint: disable=subprocess-run-check
248+ creationflags = CREATE_NO_WINDOW ,
249+ )
237250 except ValueError :
238251 try :
239252 result = subprocess .run (export_args , stdout = subprocess .PIPE ) # pylint: disable=subprocess-run-check
@@ -256,16 +269,16 @@ def extract_styles(file_path: str, symbol_type: str): # pylint: disable=too-man
256269 if headers is None :
257270 headers = r .split (Extractor .__DELIMITER )
258271 for idx , header in enumerate (headers ):
259- header = header .decode (' utf-8' )
260- if header .lower ().strip () == ' name' :
272+ header = header .decode (" utf-8" )
273+ if header .lower ().strip () == " name" :
261274 name_idx = idx
262- elif header .lower ().strip () == ' category' :
275+ elif header .lower ().strip () == " category" :
263276 category_idx = idx
264- elif header .lower ().strip () == ' object' :
277+ elif header .lower ().strip () == " object" :
265278 blob_idx = idx
266- elif header .lower ().strip () == ' tags' :
279+ elif header .lower ().strip () == " tags" :
267280 tags_idx = idx
268- elif header .lower ().strip () == 'id' :
281+ elif header .lower ().strip () == "id" :
269282 symbol_id_idx = idx
270283 continue
271284
@@ -288,14 +301,14 @@ def extract_styles(file_path: str, symbol_type: str): # pylint: disable=too-man
288301 if Extractor .is_windows ():
289302 # on windows, mdbtools does a weird thing and replaces all 0a bytes with 0a0d. Wonderful wonderful
290303 # Windows new endings come round to bite us again
291- blob = blob .replace (b' \r \n ' , b' \n ' )
304+ blob = blob .replace (b" \r \n " , b" \n " )
292305
293306 symbol = {
294307 Extractor .NAME : Extractor ._extract_text (name ),
295308 Extractor .CATEGORY : Extractor ._extract_text (category ),
296- Extractor .TAGS : Extractor ._extract_text (tags ) if tags else '' ,
309+ Extractor .TAGS : Extractor ._extract_text (tags ) if tags else "" ,
297310 Extractor .ID : Extractor ._extract_text (symbol_id ),
298- Extractor .BLOB : blob
311+ Extractor .BLOB : blob ,
299312 }
300313 raw_symbols .append (symbol )
301314
0 commit comments