Code cleanups in hscommon & external effects
This commit is contained in:
parent
f9316de244
commit
1ef5f56158
|
@ -132,7 +132,7 @@ class DupeGuru(Broadcaster):
|
|||
logging.debug("Debug mode enabled")
|
||||
Broadcaster.__init__(self)
|
||||
self.view = view
|
||||
self.appdata = desktop.special_folder_path(desktop.SpecialFolder.AppData, appname=self.NAME, portable=portable)
|
||||
self.appdata = desktop.special_folder_path(desktop.SpecialFolder.APPDATA, appname=self.NAME, portable=portable)
|
||||
if not op.exists(self.appdata):
|
||||
os.makedirs(self.appdata)
|
||||
self.app_mode = AppMode.Standard
|
||||
|
|
|
@ -336,7 +336,6 @@ def read_changelog_file(filename):
|
|||
with open(filename, "rt", encoding="utf-8") as fp:
|
||||
contents = fp.read()
|
||||
splitted = re_changelog_header.split(contents)[1:] # the first item is empty
|
||||
# splitted = [version1, date1, desc1, version2, date2, ...]
|
||||
result = []
|
||||
for version, date_str, description in iter_by_three(iter(splitted)):
|
||||
date = datetime.strptime(date_str, "%Y-%m-%d").date()
|
||||
|
@ -399,8 +398,8 @@ def create_osx_app_structure(
|
|||
# `resources`: A list of paths of files or folders going in the "Resources" folder.
|
||||
# `frameworks`: Same as above for "Frameworks".
|
||||
# `symlink_resources`: If True, will symlink resources into the structure instead of copying them.
|
||||
app = OSXAppStructure(dest, infoplist)
|
||||
app.create()
|
||||
app = OSXAppStructure(dest)
|
||||
app.create(infoplist)
|
||||
app.copy_executable(executable)
|
||||
app.copy_resources(*resources, use_symlinks=symlink_resources)
|
||||
app.copy_frameworks(*frameworks)
|
||||
|
|
|
@ -13,8 +13,8 @@ import traceback
|
|||
# Taken from http://bzimmer.ziclix.com/2008/12/17/python-thread-dumps/
|
||||
def stacktraces():
|
||||
code = []
|
||||
for threadId, stack in sys._current_frames().items():
|
||||
code.append("\n# ThreadID: %s" % threadId)
|
||||
for thread_id, stack in sys._current_frames().items():
|
||||
code.append("\n# ThreadID: %s" % thread_id)
|
||||
for filename, lineno, name, line in traceback.extract_stack(stack):
|
||||
code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
|
||||
if line:
|
||||
|
|
|
@ -11,8 +11,8 @@ import logging
|
|||
|
||||
|
||||
class SpecialFolder:
|
||||
AppData = 1
|
||||
Cache = 2
|
||||
APPDATA = 1
|
||||
CACHE = 2
|
||||
|
||||
|
||||
def open_url(url):
|
||||
|
@ -55,7 +55,7 @@ try:
|
|||
_reveal_path = proxy.revealPath_
|
||||
|
||||
def _special_folder_path(special_folder, appname=None, portable=False):
|
||||
if special_folder == SpecialFolder.Cache:
|
||||
if special_folder == SpecialFolder.CACHE:
|
||||
base = proxy.getCachePath()
|
||||
else:
|
||||
base = proxy.getAppdataPath()
|
||||
|
@ -89,7 +89,7 @@ except ImportError:
|
|||
_open_path(op.dirname(str(path)))
|
||||
|
||||
def _special_folder_path(special_folder, appname=None, portable=False):
|
||||
if special_folder == SpecialFolder.Cache:
|
||||
if special_folder == SpecialFolder.CACHE:
|
||||
if ISWINDOWS and portable:
|
||||
folder = op.join(executable_folder(), "cache")
|
||||
else:
|
||||
|
@ -104,9 +104,11 @@ except ImportError:
|
|||
logging.warning("Can't setup desktop functions!")
|
||||
|
||||
def _open_path(path):
|
||||
# Dummy for tests
|
||||
pass
|
||||
|
||||
def _reveal_path(path):
|
||||
# Dummy for tests
|
||||
pass
|
||||
|
||||
def _special_folder_path(special_folder, appname=None, portable=False):
|
||||
|
|
|
@ -146,24 +146,29 @@ class Job:
|
|||
|
||||
class NullJob:
|
||||
def __init__(self, *args, **kwargs):
|
||||
# Null job does nothing
|
||||
pass
|
||||
|
||||
def add_progress(self, *args, **kwargs):
|
||||
# Null job does nothing
|
||||
pass
|
||||
|
||||
def check_if_cancelled(self):
|
||||
# Null job does nothing
|
||||
pass
|
||||
|
||||
def iter_with_progress(self, sequence, *args, **kwargs):
|
||||
return iter(sequence)
|
||||
|
||||
def start_job(self, *args, **kwargs):
|
||||
# Null job does nothing
|
||||
pass
|
||||
|
||||
def start_subjob(self, *args, **kwargs):
|
||||
return NullJob()
|
||||
|
||||
def set_progress(self, *args, **kwargs):
|
||||
# Null job does nothing
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@ PO2COCOA = {
|
|||
|
||||
COCOA2PO = {v: k for k, v in PO2COCOA.items()}
|
||||
|
||||
STRING_EXT = ".strings"
|
||||
|
||||
|
||||
def get_langs(folder):
|
||||
return [name for name in os.listdir(folder) if op.isdir(op.join(folder, name))]
|
||||
|
@ -152,7 +154,7 @@ def strings2pot(target, dest):
|
|||
|
||||
|
||||
def allstrings2pot(lprojpath, dest, excludes=None):
|
||||
allstrings = files_with_ext(lprojpath, ".strings")
|
||||
allstrings = files_with_ext(lprojpath, STRING_EXT)
|
||||
if excludes:
|
||||
allstrings = [p for p in allstrings if op.splitext(op.basename(p))[0] not in excludes]
|
||||
for strings_path in allstrings:
|
||||
|
@ -210,7 +212,7 @@ def generate_cocoa_strings_from_code(code_folder, dest_folder):
|
|||
def generate_cocoa_strings_from_xib(xib_folder):
|
||||
xibs = [op.join(xib_folder, fn) for fn in os.listdir(xib_folder) if fn.endswith(".xib")]
|
||||
for xib in xibs:
|
||||
dest = xib.replace(".xib", ".strings")
|
||||
dest = xib.replace(".xib", STRING_EXT)
|
||||
print_and_do("ibtool {} --generate-strings-file {}".format(xib, dest))
|
||||
print_and_do("iconv -f utf-16 -t utf-8 {0} | tee {0}".format(dest))
|
||||
|
||||
|
@ -226,6 +228,6 @@ def localize_stringsfile(stringsfile, dest_root_folder):
|
|||
|
||||
|
||||
def localize_all_stringsfiles(src_folder, dest_root_folder):
|
||||
stringsfiles = [op.join(src_folder, fn) for fn in os.listdir(src_folder) if fn.endswith(".strings")]
|
||||
stringsfiles = [op.join(src_folder, fn) for fn in os.listdir(src_folder) if fn.endswith(STRING_EXT)]
|
||||
for path in stringsfiles:
|
||||
localize_stringsfile(path, dest_root_folder)
|
||||
|
|
|
@ -167,10 +167,10 @@ def getFilesForName(name):
|
|||
# check for glob chars
|
||||
if containsAny(name, "*?[]"):
|
||||
files = glob.glob(name)
|
||||
list = []
|
||||
file_list = []
|
||||
for file in files:
|
||||
list.extend(getFilesForName(file))
|
||||
return list
|
||||
file_list.extend(getFilesForName(file))
|
||||
return file_list
|
||||
|
||||
# try to find module or package
|
||||
name = _get_modpkg_path(name)
|
||||
|
@ -179,9 +179,9 @@ def getFilesForName(name):
|
|||
|
||||
if os.path.isdir(name):
|
||||
# find all python files in directory
|
||||
list = []
|
||||
os.walk(name, _visit_pyfiles, list)
|
||||
return list
|
||||
file_list = []
|
||||
os.walk(name, _visit_pyfiles, file_list)
|
||||
return file_list
|
||||
elif os.path.exists(name):
|
||||
# a single file
|
||||
return [name]
|
||||
|
|
|
@ -131,11 +131,11 @@ def install_gettext_trans(base_folder, lang):
|
|||
def install_gettext_trans_under_cocoa():
|
||||
from cocoa import proxy
|
||||
|
||||
resFolder = proxy.getResourcePath()
|
||||
baseFolder = op.join(resFolder, "locale")
|
||||
currentLang = proxy.systemLang()
|
||||
install_gettext_trans(baseFolder, currentLang)
|
||||
localename = get_locale_name(currentLang)
|
||||
res_folder = proxy.getResourcePath()
|
||||
base_folder = op.join(res_folder, "locale")
|
||||
current_lang = proxy.systemLang()
|
||||
install_gettext_trans(base_folder, current_lang)
|
||||
localename = get_locale_name(current_lang)
|
||||
if localename is not None:
|
||||
locale.setlocale(locale.LC_ALL, localename)
|
||||
|
||||
|
|
|
@ -177,13 +177,13 @@ def pluralize(number, word, decimals=0, plural_word=None):
|
|||
``plural_word``: If the plural rule for word is more complex than adding a 's', specify a plural
|
||||
"""
|
||||
number = round(number, decimals)
|
||||
format = "%%1.%df %%s" % decimals
|
||||
plural_format = "%%1.%df %%s" % decimals
|
||||
if number > 1:
|
||||
if plural_word is None:
|
||||
word += "s"
|
||||
else:
|
||||
word = plural_word
|
||||
return format % (number, word)
|
||||
return plural_format % (number, word)
|
||||
|
||||
|
||||
def format_time(seconds, with_hours=True):
|
||||
|
@ -252,7 +252,7 @@ def format_size(size, decimal=0, forcepower=-1, showdesc=True):
|
|||
div = SIZE_VALS[i - 1]
|
||||
else:
|
||||
div = 1
|
||||
format = "%%%d.%df" % (decimal, decimal)
|
||||
size_format = "%%%d.%df" % (decimal, decimal)
|
||||
negative = size < 0
|
||||
divided_size = (0.0 + abs(size)) / div
|
||||
if decimal == 0:
|
||||
|
@ -261,7 +261,7 @@ def format_size(size, decimal=0, forcepower=-1, showdesc=True):
|
|||
divided_size = ceil(divided_size * (10 ** decimal)) / (10 ** decimal)
|
||||
if negative:
|
||||
divided_size *= -1
|
||||
result = format % divided_size
|
||||
result = size_format % divided_size
|
||||
if showdesc:
|
||||
result += " " + SIZE_DESC[i]
|
||||
return result
|
||||
|
@ -292,7 +292,7 @@ def multi_replace(s, replace_from, replace_to=""):
|
|||
the same length as ``replace_from``, it will be transformed into a list.
|
||||
"""
|
||||
if isinstance(replace_to, str) and (len(replace_from) != len(replace_to)):
|
||||
replace_to = [replace_to for r in replace_from]
|
||||
replace_to = [replace_to for _ in replace_from]
|
||||
if len(replace_from) != len(replace_to):
|
||||
raise ValueError("len(replace_from) must be equal to len(replace_to)")
|
||||
replace = list(zip(replace_from, replace_to))
|
||||
|
|
Loading…
Reference in New Issue