mirror of
https://github.com/ciromattia/kcc
synced 2026-09-01 16:37:06 +00:00
Add number padding and lowering for file names (not directory)
This commit is contained in:
+8
-3
@@ -536,15 +536,20 @@ def getWorkFolder(afile):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
def slugify(value):
|
def slugify(value, lower=True, digitpadding=True):
|
||||||
"""
|
"""
|
||||||
Normalizes string, converts to lowercase, removes non-alpha characters,
|
Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||||
and converts spaces to hyphens.
|
and converts spaces to hyphens.
|
||||||
"""
|
"""
|
||||||
import unicodedata
|
import unicodedata
|
||||||
value = unicodedata.normalize('NFKD', unicode(value)).encode('ascii', 'ignore')
|
value = unicodedata.normalize('NFKD', unicode(value, 'UTF-8')).encode('ascii', 'ignore')
|
||||||
value = re.sub('[^\w\s-]', '', value).strip()
|
value = re.sub('[^\w\s-]', '', value).strip()
|
||||||
value = re.sub('[-\s]+', '-', value)
|
value = re.sub('[-\s]+', '-', value)
|
||||||
|
if lower:
|
||||||
|
value = value.lower()
|
||||||
|
if digitpadding:
|
||||||
|
value = re.sub(r'([0-9]+)', r'00000\1', value)
|
||||||
|
value = re.sub(r'0*([0-9]{6,})', r'\1', value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@@ -556,7 +561,7 @@ def slugifyFileTree(filetree):
|
|||||||
os.path.join(root, slugify(splitname[0]) + splitname[1]))
|
os.path.join(root, slugify(splitname[0]) + splitname[1]))
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
slugifyFileTree(os.path.join(root, name))
|
slugifyFileTree(os.path.join(root, name))
|
||||||
os.rename(os.path.join(root, name), os.path.join(root, slugify(name)))
|
os.rename(os.path.join(root, name), os.path.join(root, slugify(name, False)))
|
||||||
|
|
||||||
|
|
||||||
def Copyright():
|
def Copyright():
|
||||||
|
|||||||
Reference in New Issue
Block a user