Commits

Stéphane Klein  committed cf11016

First import

  • Participants

Comments (0)

Files changed (3)

+syntax: glob
+
+.installed.cfg
+bin
+develop-eggs
+
+*.egg-info
+
+tmp
+build
+dist
+*.pyc
+src/convert_nfd_unicode_filesystem_to_nfc_unicode.egg-info/
+from setuptools import setup, find_packages
+import sys, os
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+version = '0.1.0'
+
+install_requires = [
+    'docopt'
+]
+
+
+setup(
+    name='convert-nfd-unicode-filesystem-to-nfc-unicode',
+    version=version,
+    description="Convert Mac OSX NFD unicode filename to NFC unicode",
+    classifiers=[
+    ],
+    keywords='MacOSX unicode NFD NFC',
+    author='Stephane Klein',
+    author_email='contact@stephane-klein.info',
+    url='',
+    license='',
+    packages=find_packages('src'),
+    package_dir={'': 'src'},
+    include_package_data=True,
+    zip_safe=False,
+    install_requires=install_requires,
+    entry_points={
+        'console_scripts': [
+            'convert-nfd-unicode-filesystem-to-nfc-unicode=convertnfdunicodefilesystemtonfcunicode:main'
+        ]
+    }
+)

File src/convertnfdunicodefilesystemtonfcunicode/__init__.py

+import os
+import sys
+import unicodedata
+
+from docopt import docopt
+
+
+def fix_unicode(path, verbose=True):
+    for root, dirs, files in os.walk(unicode(path), topdown=False):
+        for entry in files:
+            nfc = unicodedata.normalize('NFC', entry)
+            if entry != nfc:
+                os.rename(
+                    os.path.join(root, entry),
+                    os.path.join(root, nfc))
+
+                if verbose:
+                    print os.path.join(root, nfc)
+
+        rootparent, rootentry = os.path.split(root)
+        nfc = unicodedata.normalize('NFC', rootentry)
+        if rootentry != nfc:
+            os.rename(root, os.path.join(rootparent, nfc))
+            if verbose:
+                print os.path.join(rootparent, nfc)
+
+
+def main():
+    arguments = docopt(
+"""Usage:
+  convert-nfd-unicode-filesystem-to-nfc-unicode <path>
+  convert-nfd-unicode-filesystem-to-nfc-unicode -h | --help | --version
+
+""",
+        version='0.1.0'
+    )
+    path = arguments['<path>']
+    if not os.path.exists(path):
+        sys.exit('Error, folder not found %s' % path)
+
+    fix_unicode(path)