|
|
@ -11,20 +11,25 @@ import shutil
|
|
|
|
import sys
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
from datetime import date
|
|
|
|
from datetime import date
|
|
|
|
|
|
|
|
from unicodedata import normalize
|
|
|
|
|
|
|
|
|
|
|
|
_slugify_strip_re = re.compile(r'[^\w\s-]')
|
|
|
|
_punctuation_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')
|
|
|
|
_slugify_hyphenate_re = re.compile(r'[-\s]+')
|
|
|
|
|
|
|
|
def slugify(value):
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
Normalizes string, converts to lowercase, removes non-alpha characters,
|
|
|
|
|
|
|
|
and converts spaces to hyphens.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
From Django's "django/template/defaultfilters.py".
|
|
|
|
def slugify(text, delim='-'):
|
|
|
|
'''
|
|
|
|
"""
|
|
|
|
import unicodedata
|
|
|
|
Generate an ASCII-only slug.
|
|
|
|
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
|
|
|
|
"""
|
|
|
|
value = unicode(_slugify_strip_re.sub('', value).strip().lower())
|
|
|
|
|
|
|
|
return _slugify_hyphenate_re.sub('-', value)
|
|
|
|
result = []
|
|
|
|
|
|
|
|
for word in _punctuation_re.split(text.lower()):
|
|
|
|
|
|
|
|
word = normalize('NFKD', word) \
|
|
|
|
|
|
|
|
.encode('ascii', 'ignore') \
|
|
|
|
|
|
|
|
.decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if word:
|
|
|
|
|
|
|
|
result.append(word)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return delim.join(result)
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
|
|
|
def usage():
|
|
|
|
return 'Usage: mv-to-docs [SRC_DOC] [CATEGORY] [MESSAGE]'
|
|
|
|
return 'Usage: mv-to-docs [SRC_DOC] [CATEGORY] [MESSAGE]'
|
|
|
@ -43,18 +48,19 @@ def main(file_name='', dir_name='', message = ''):
|
|
|
|
print('could not find path → creating directory: {}'.format(doc_path))
|
|
|
|
print('could not find path → creating directory: {}'.format(doc_path))
|
|
|
|
os.mkdir(doc_path)
|
|
|
|
os.mkdir(doc_path)
|
|
|
|
|
|
|
|
|
|
|
|
path_with_year = "%s/%s".format((doc_path, file_date.strftime("%Y")))
|
|
|
|
year = file_date.strftime("%Y")
|
|
|
|
|
|
|
|
path_with_year = '{}/{}'.format(doc_path, year)
|
|
|
|
if not os.path.exists(path_with_year):
|
|
|
|
if not os.path.exists(path_with_year):
|
|
|
|
os.mkdir(path_with_year)
|
|
|
|
os.mkdir(path_with_year)
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
new_file_path = '%s/%s_%s.%s'.format(path_with_year,
|
|
|
|
new_file_path = '{}/{}_{}.{}'.format(path_with_year,
|
|
|
|
file_date.strftime("%Y-%m-%d"),
|
|
|
|
file_date,
|
|
|
|
message,
|
|
|
|
message,
|
|
|
|
file_type)
|
|
|
|
file_type)
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.isfile(new_file_path):
|
|
|
|
if not os.path.isfile(new_file_path):
|
|
|
|
print("Moving file '%s' to '%s'" % (file_name, new_file_path))
|
|
|
|
print("Moving file '{}' to '{}'".format(file_name, new_file_path))
|
|
|
|
shutil.copyfile(file_name, new_file_path)
|
|
|
|
shutil.copyfile(file_name, new_file_path)
|
|
|
|
os.unlink(file_name)
|
|
|
|
os.unlink(file_name)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|