Use voussoirkit getpermission.

This commit is contained in:
voussoir 2020-02-16 09:50:46 -08:00
parent 845eebf40f
commit c36c9d2584

View file

@ -9,6 +9,7 @@ import traceback
import zipfile import zipfile
from voussoirkit import clipext from voussoirkit import clipext
from voussoirkit import getpermission
FILENAME_BADCHARS = '\\/:*?<>|"' FILENAME_BADCHARS = '\\/:*?<>|"'
@ -20,10 +21,6 @@ def sanitize_filename(name):
name = name.replace(c, '-') name = name.replace(c, '-')
return name return name
def prompt_permission(prompt):
answer = input(prompt)
return answer.lower() in {'yes', 'y'}
def get_webstore_name_version(extension_id): def get_webstore_name_version(extension_id):
url = WEBSTORE_URL.format(extension_id=extension_id) url = WEBSTORE_URL.format(extension_id=extension_id)
response = requests.get(url) response = requests.get(url)
@ -79,9 +76,11 @@ def getcrx(extension_id, auto_overwrite=None):
crx_filename = sanitize_filename(crx_filename) crx_filename = sanitize_filename(crx_filename)
if os.path.isfile(crx_filename): if os.path.isfile(crx_filename):
if auto_overwrite is True:
permission = True
if auto_overwrite is None: if auto_overwrite is None:
message = '"%s" already exists. Overwrite?' % crx_filename message = f'"{crx_filename}" already exists. Overwrite?'
permission = prompt_permission(message) permission = getpermission.getpermission(message)
else: else:
permission = False permission = False
else: else:
@ -90,7 +89,7 @@ def getcrx(extension_id, auto_overwrite=None):
if permission: if permission:
crx_handle = open(crx_filename, 'wb') crx_handle = open(crx_filename, 'wb')
crx_handle.write(response.content) crx_handle.write(response.content)
print('Downloaded "%s".' % crx_filename) print(f'Downloaded "{crx_filename}".')
def getcrx_argparse(args): def getcrx_argparse(args):
extension_ids = [] extension_ids = []