Import stringtools and remove functions covered by that.
This commit is contained in:
parent
67108ec617
commit
7b8301b324
1 changed files with 10 additions and 29 deletions
39
brename.py
39
brename.py
|
@ -21,13 +21,23 @@ import unicodedata
|
||||||
from voussoirkit import getpermission
|
from voussoirkit import getpermission
|
||||||
from voussoirkit import safeprint
|
from voussoirkit import safeprint
|
||||||
from voussoirkit import spinal
|
from voussoirkit import spinal
|
||||||
|
from voussoirkit import stringtools
|
||||||
|
|
||||||
|
# These variables are provided so that if you have any difficulty typing
|
||||||
|
# literal quotes etc into your command line, you can just use these variable
|
||||||
|
# names in your eval string.
|
||||||
apostrophe = "'"
|
apostrophe = "'"
|
||||||
dot = '.'
|
dot = '.'
|
||||||
hyphen = '-'
|
hyphen = '-'
|
||||||
quote = '"'
|
quote = '"'
|
||||||
space = ' '
|
space = ' '
|
||||||
underscore = '_'
|
underscore = '_'
|
||||||
|
|
||||||
|
# For backwards compatibility, these names which were once locally defined
|
||||||
|
# functions are now just references to stringtools.
|
||||||
|
excise = stringtools.excise
|
||||||
|
title = stringtools.title_capitalize
|
||||||
|
|
||||||
def unicode_normalize(s):
|
def unicode_normalize(s):
|
||||||
return unicodedata.normalize('NFC', s)
|
return unicodedata.normalize('NFC', s)
|
||||||
|
|
||||||
|
@ -70,18 +80,6 @@ def brename(transformation, autoyes=False, recurse=False):
|
||||||
pairs = sorted(pairs, reverse=True)
|
pairs = sorted(pairs, reverse=True)
|
||||||
loop(pairs, dry=False)
|
loop(pairs, dry=False)
|
||||||
|
|
||||||
def excise(s, mark_left, mark_right):
|
|
||||||
'''
|
|
||||||
Remove the text between the left and right landmarks, inclusive, returning
|
|
||||||
the rest of the text.
|
|
||||||
|
|
||||||
excise('What a wonderful day [soundtrack].mp3', ' [', ']') ->
|
|
||||||
returns 'What a wonderful day.mp3'
|
|
||||||
'''
|
|
||||||
if mark_left in s and mark_right in s:
|
|
||||||
return s.split(mark_left)[0] + s.split(mark_right)[-1]
|
|
||||||
return s
|
|
||||||
|
|
||||||
def longest_length(li):
|
def longest_length(li):
|
||||||
longest = 0
|
longest = 0
|
||||||
for item in li:
|
for item in li:
|
||||||
|
@ -96,23 +94,6 @@ def loop(pairs, dry=False):
|
||||||
else:
|
else:
|
||||||
os.rename(old, new)
|
os.rename(old, new)
|
||||||
|
|
||||||
def title(text):
|
|
||||||
(text, extension) = os.path.splitext(text)
|
|
||||||
text = text.title()
|
|
||||||
if ' ' in text:
|
|
||||||
(first, rest) = text.split(' ', 1)
|
|
||||||
else:
|
|
||||||
(first, rest) = (text, '')
|
|
||||||
rest = ' %s ' % rest
|
|
||||||
for article in ['The', 'A', 'An', 'At', 'To', 'In', 'Of', 'From', 'And']:
|
|
||||||
article = ' %s ' % article
|
|
||||||
rest = rest.replace(article, article.lower())
|
|
||||||
rest = rest.strip()
|
|
||||||
if rest != '':
|
|
||||||
rest = ' ' + rest
|
|
||||||
text = first + rest + extension
|
|
||||||
return text
|
|
||||||
|
|
||||||
def brename_argparse(args):
|
def brename_argparse(args):
|
||||||
brename(args.transformation, autoyes=args.autoyes, recurse=args.recurse)
|
brename(args.transformation, autoyes=args.autoyes, recurse=args.recurse)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue