Skip to content

Commit bcbb50f

Browse files
committed
update indentation
1 parent 6669bcb commit bcbb50f

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

update_example_snippets.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Update or download example snippets
1+
# update snippets
22
#
3-
# Automatically download and update a collection of snippets to your local snippet folder
3+
# Automatically download and update this collection of snippets to your local snippet folder
44

55
from zipfile import ZipFile
66
from tempfile import TemporaryFile
@@ -9,48 +9,49 @@
99
#TODO: Merge remote with local description or hotkey changes (AKA: if filename matches, skip the first two lines, truncate, re-write the rest)
1010

1111
domain = b'https://gist.github.com'
12-
path = b'/psifertex/6fbc7532f536775194edd26290892ef7' # Feel free to adapt to your own setup
13-
subfolder = 'examples' # Change to save the snippets to a different sub-folder
12+
path = b'/psifertex/6fbc7532f536775194edd26290892ef7' # Feel free to adapt to your own setup
13+
subfolder = 'default' # Change to save the snippets to a different sub-folder
1414
tab2space = False
1515
width = 4
1616

1717
def download(url):
18-
provider = next(iter(DownloadProvider)).create_instance()
19-
code, data = provider.get_response(url)
20-
if code == 0:
21-
return data
22-
else:
23-
raise ConnectionError("Unsuccessful download of %s" % url)
18+
# Can also use 'CoreDownloadProvider' or 'PythonDownloadProvider' as keys here
19+
provider = DownloadProvider[Settings().get_string('network.downloadProviderName')].create_instance()
20+
code, data = provider.get_response(url)
21+
if code == 0:
22+
return data
23+
else:
24+
raise ConnectionError("Unsuccessful download of %s" % url)
2425

2526
def update_snippets():
26-
if not interaction.show_message_box('Warning', "Use at your own risk. Do you want to automatically overwrite local snippets from gist?", buttons=MessageBoxButtonSet.YesNoButtonSet):
27-
return
28-
snippetPath = os.path.realpath(os.path.join(user_plugin_path(), '..', 'snippets', subfolder))
29-
if not os.path.isdir(snippetPath):
30-
os.makedirs(snippetPath)
31-
url = domain + path
32-
log_info("Downloading from: %s" % url)
33-
source = download(url)
34-
zipPath = [s for s in source.split(b'\"') if s.endswith(b'.zip')]
35-
if len(zipPath) != 1:
36-
log_error("Update failed.")
37-
return
38-
url = domain + zipPath[0]
27+
if not interaction.show_message_box('Warning', "Use at your own risk. Do you want to automatically overwrite local snippets from gist?", buttons=MessageBoxButtonSet.YesNoButtonSet):
28+
return
29+
snippetPath = os.path.realpath(os.path.join(user_plugin_path(), '..', 'snippets', subfolder))
30+
if not os.path.isdir(snippetPath):
31+
os.makedirs(snippetPath)
32+
url = domain + path
33+
log_info("Downloading from: %s" % url)
34+
source = download(url)
35+
zipPath = [s for s in source.split(b'\"') if s.endswith(b'.zip')]
36+
if len(zipPath) != 1:
37+
log_error("Update failed.")
38+
return
39+
url = domain + zipPath[0]
3940

40-
log_info("Downloading from: %s" % url)
41-
zip = download(url)
42-
with TemporaryFile() as f:
43-
f.write(zip)
44-
with ZipFile(f, 'r') as zip:
45-
for item in zip.infolist():
46-
if item.filename[-1] == '/':
47-
continue
48-
basename = os.path.basename(item.filename)
49-
with open(os.path.join(snippetPath, basename), 'wb') as f:
50-
if tab2space:
51-
f.write(zip.read(item).replace(b'\t', b' ' * width))
52-
else:
53-
f.write(zip.read(item))
54-
log_info("Extracting %s" % item.filename)
41+
log_info("Downloading from: %s" % url)
42+
zip = download(url)
43+
with TemporaryFile() as f:
44+
f.write(zip)
45+
with ZipFile(f, 'r') as zip:
46+
for item in zip.infolist():
47+
if item.filename[-1] == '/':
48+
continue
49+
basename = os.path.basename(item.filename)
50+
with open(os.path.join(snippetPath, basename), 'wb') as f:
51+
if tab2space:
52+
f.write(zip.read(item).replace(b'\t', b' ' * width))
53+
else:
54+
f.write(zip.read(item))
55+
log_info("Extracting %s" % item.filename)
5556

5657
update_snippets()

0 commit comments

Comments
 (0)