mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Extract a method or a function.
This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well.
This commit is contained in:
parent
2bec58be2d
commit
efddc917b2
1 changed files with 29 additions and 26 deletions
|
@ -1239,6 +1239,32 @@ Please select a %s type %s.
|
||||||
#
|
#
|
||||||
# init tiles
|
# init tiles
|
||||||
#
|
#
|
||||||
|
def _init_tiles_process_dir(self, ext_re, dirname, found, t):
|
||||||
|
"""docstring for _init_tiles_process_die"""
|
||||||
|
names = []
|
||||||
|
if dirname and os.path.isdir(dirname):
|
||||||
|
names = os.listdir(dirname)
|
||||||
|
for name in names:
|
||||||
|
if not name or not ext_re.search(name):
|
||||||
|
continue
|
||||||
|
f = os.path.join(dirname, name)
|
||||||
|
if not os.path.isfile(f):
|
||||||
|
continue
|
||||||
|
tile = Tile()
|
||||||
|
tile.filename = f
|
||||||
|
n = ext_re.sub("", name)
|
||||||
|
if os.path.split(dirname)[-1] == 'stretch':
|
||||||
|
tile.stretch = 1
|
||||||
|
if os.path.split(dirname)[-1] == 'save-aspect':
|
||||||
|
tile.stretch = 1
|
||||||
|
tile.save_aspect = 1
|
||||||
|
# n = re.sub("[-_]", " ", n)
|
||||||
|
n = n.replace('_', ' ')
|
||||||
|
tile.name = n
|
||||||
|
key = n.lower()
|
||||||
|
if key not in t:
|
||||||
|
t.add(key)
|
||||||
|
found.append((n, tile))
|
||||||
|
|
||||||
def initTiles(self):
|
def initTiles(self):
|
||||||
manager = self.tabletile_manager
|
manager = self.tabletile_manager
|
||||||
|
@ -1252,33 +1278,10 @@ Please select a %s type %s.
|
||||||
# print dirs
|
# print dirs
|
||||||
s = "((\\" + ")|(\\".join(IMAGE_EXTENSIONS) + "))$"
|
s = "((\\" + ")|(\\".join(IMAGE_EXTENSIONS) + "))$"
|
||||||
ext_re = re.compile(s, re.I | re.U)
|
ext_re = re.compile(s, re.I | re.U)
|
||||||
found, t = [], {}
|
found, t = [], set()
|
||||||
for dir in dirs:
|
for dirname in dirs:
|
||||||
try:
|
try:
|
||||||
names = []
|
self._init_tiles_process_dir(ext_re, dirname, found, t)
|
||||||
if dir and os.path.isdir(dir):
|
|
||||||
names = os.listdir(dir)
|
|
||||||
for name in names:
|
|
||||||
if not name or not ext_re.search(name):
|
|
||||||
continue
|
|
||||||
f = os.path.join(dir, name)
|
|
||||||
if not os.path.isfile(f):
|
|
||||||
continue
|
|
||||||
tile = Tile()
|
|
||||||
tile.filename = f
|
|
||||||
n = ext_re.sub("", name)
|
|
||||||
if os.path.split(dir)[-1] == 'stretch':
|
|
||||||
tile.stretch = 1
|
|
||||||
if os.path.split(dir)[-1] == 'save-aspect':
|
|
||||||
tile.stretch = 1
|
|
||||||
tile.save_aspect = 1
|
|
||||||
# n = re.sub("[-_]", " ", n)
|
|
||||||
n = n.replace('_', ' ')
|
|
||||||
tile.name = n
|
|
||||||
key = n.lower()
|
|
||||||
if key not in t:
|
|
||||||
t[key] = 1
|
|
||||||
found.append((n, tile))
|
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
pass
|
pass
|
||||||
# register tiles
|
# register tiles
|
||||||
|
|
Loading…
Add table
Reference in a new issue