Skip to content

Commit

Permalink
Fixed directory sorting (close #235)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Oct 13, 2017
1 parent f44bf59 commit 658d2f3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions kindlecomicconverter/comic2ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def sanitizeTree(filetree):
for root, dirs, files in os.walk(filetree, False):
for name in files:
splitname = os.path.splitext(name)
slugified = slugify(splitname[0])
slugified = slugify(splitname[0], False)
while os.path.exists(os.path.join(root, slugified + splitname[1])) and splitname[0].upper()\
!= slugified.upper():
slugified += "A"
Expand All @@ -709,7 +709,7 @@ def sanitizeTree(filetree):
os.replace(key, newKey)
for name in dirs:
tmpName = name
slugified = slugify(name)
slugified = slugify(name, True)
while os.path.exists(os.path.join(root, slugified)) and name.upper() != slugified.upper():
slugified += "A"
chapterNames[slugified] = tmpName
Expand Down Expand Up @@ -856,8 +856,11 @@ def createNewTome():
return tomePath, tomePathRoot


def slugify(value):
value = slugifyExt(value)
def slugify(value, isDir):
if isDir:
value = slugifyExt(value, regex_pattern=r'[^-a-z0-9_\.]+')
else:
value = slugifyExt(value)
value = sub(r'0*([0-9]{4,})', r'\1', sub(r'([0-9]+)', r'0000\1', value, count=2))
return value

Expand Down

0 comments on commit 658d2f3

Please sign in to comment.