Skip to content

Commit 48a5d7a

Browse files
committed
Ruff format
1 parent d3cb256 commit 48a5d7a

File tree

270 files changed

+20494
-16669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

270 files changed

+20494
-16669
lines changed

bintools/extract_bin.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,64 @@
99
import argparse
1010

1111
parser = argparse.ArgumentParser()
12-
parser.add_argument("file", help="style file to extract",nargs='?')
12+
parser.add_argument("file", help="style file to extract", nargs="?")
1313
args = parser.parse_args()
1414
print(args.file)
1515

1616
try:
17-
driver = [d for d in pyodbc.drivers() if 'Microsoft Access' in d][0]
17+
driver = [d for d in pyodbc.drivers() if "Microsoft Access" in d][0]
1818
except AttributeError:
1919
driver = None
2020

2121

2222
def clean_symbol_name_for_file(symbol_name):
2323
"""nasty little function to remove some characters which will choke"""
2424
file_name = symbol_name
25-
file_name = file_name.replace('/', '_')
26-
file_name = file_name.replace('>', '_')
27-
file_name = file_name.replace('\\', '_')
28-
file_name = file_name.replace('?', '_')
29-
file_name = file_name.replace('*', '_')
25+
file_name = file_name.replace("/", "_")
26+
file_name = file_name.replace(">", "_")
27+
file_name = file_name.replace("\\", "_")
28+
file_name = file_name.replace("?", "_")
29+
file_name = file_name.replace("*", "_")
3030
return file_name
3131

32+
3233
if not args.file:
33-
styles=[('fill','fill'),('line','line'),('marker','marker'),('fill105','fill')]
34-
styles=[(os.path.join('styles',s[0] + '.style'),s[1]) for s in styles]
35-
output_path = os.path.join('styles', 'bin')
34+
styles = [
35+
("fill", "fill"),
36+
("line", "line"),
37+
("marker", "marker"),
38+
("fill105", "fill"),
39+
]
40+
styles = [(os.path.join("styles", s[0] + ".style"), s[1]) for s in styles]
41+
output_path = os.path.join("styles", "bin")
3642
else:
37-
styles=[(args.file, 'fill'),(args.file, 'line'),(args.file, 'marker')]
43+
styles = [(args.file, "fill"), (args.file, "line"), (args.file, "marker")]
3844
output_path, _ = os.path.split(args.file)
3945

40-
for (fill_style_db,type) in styles:
46+
for fill_style_db, type in styles:
4147
if driver is not None:
4248
# windows
43-
con = pyodbc.connect('DRIVER={};DBQ={}'.format(driver,fill_style_db))
49+
con = pyodbc.connect("DRIVER={};DBQ={}".format(driver, fill_style_db))
4450
else:
4551
# linux
46-
con = pyodbc.connect('DRIVER=/usr/lib64/libmdbodbc.so;DBQ={}'.format(fill_style_db))
52+
con = pyodbc.connect(
53+
"DRIVER=/usr/lib64/libmdbodbc.so;DBQ={}".format(fill_style_db)
54+
)
4755

4856
# grab fill symbols
4957
cur = con.cursor()
50-
SQL = 'SELECT name, object FROM [{} Symbols];'.format(type)
58+
SQL = "SELECT name, object FROM [{} Symbols];".format(type)
5159
rows = cur.execute(SQL).fetchall()
5260
cur.close()
5361
con.close()
5462

5563
for r in rows:
56-
symbol_name=r[0]
57-
blob=r[1]
64+
symbol_name = r[0]
65+
blob = r[1]
5866

59-
out_filename=clean_symbol_name_for_file(symbol_name) + '.bin'
60-
file = os.path.join(output_path,out_filename)
67+
out_filename = clean_symbol_name_for_file(symbol_name) + ".bin"
68+
file = os.path.join(output_path, out_filename)
6169

6270
print(file)
63-
with open(file, 'wb') as e:
71+
with open(file, "wb") as e:
6472
e.write(blob)
65-

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tool.ruff]
2+
exclude = ["slyr_community/parser/cim", "slyr_community/parser/color_lut.py"]

slyr_community/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626

2727
def classFactory(iface):
2828
"""invoke plugin"""
29-
from slyr_community.plugin import SlyrPlugin # pylint: disable=import-outside-toplevel
29+
from slyr_community.plugin import SlyrPlugin # pylint: disable=import-outside-toplevel
30+
3031
return SlyrPlugin(iface)

slyr_community/bintools/extractor.py

Lines changed: 84 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -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

slyr_community/bintools/file_utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ class FileUtils:
3333
def clean_symbol_name_for_file(symbol_name):
3434
"""nasty little function to remove some characters which will choke"""
3535
file_name = symbol_name
36-
file_name = file_name.replace('/', '_')
37-
file_name = file_name.replace('>', '_')
38-
file_name = file_name.replace('<', '_')
39-
file_name = file_name.replace('\\', '_')
40-
file_name = file_name.replace('?', '_')
41-
file_name = file_name.replace('*', '_')
42-
file_name = file_name.replace('"', '_')
43-
file_name = file_name.replace(':', '_')
36+
file_name = file_name.replace("/", "_")
37+
file_name = file_name.replace(">", "_")
38+
file_name = file_name.replace("<", "_")
39+
file_name = file_name.replace("\\", "_")
40+
file_name = file_name.replace("?", "_")
41+
file_name = file_name.replace("*", "_")
42+
file_name = file_name.replace('"', "_")
43+
file_name = file_name.replace(":", "_")
4444
return file_name.strip()

0 commit comments

Comments
 (0)