Commits

Stéphane Klein  committed ba79a66

Rename package to nfd2nfc

  • Participants
  • Parent commits c595bcf

Comments (0)

Files changed (5)

 build
 dist
 *.pyc
-src/convert_nfd_unicode_filesystem_to_nfc_unicode.egg-info/
+src/nfd2nfc/
 but it can also contain file encoded in NFD mode.
 You can use this tool to convert NFD to NFC.
 
+
 Install
 =======
 
 ::
 
-    $ pip install https://bitbucket.org/harobed/convert-nfd-unicode-filesystem-to-nfc-unicode/downloads/convert-nfd-unicode-filesystem-to-nfc-unicode-0.1.0.tar.gz
+    $ pip install https://bitbucket.org/harobed/convert-nfd-unicode-filesystem-to-nfc-unicode/downloads/nfd2nfc-0.1.0.tar.gz
 
 
 Usage
 
 ::
 
-    $ convert-nfd-unicode-filesystem-to-nfc-unicode -h
+    $ nfd2nfc -h
     This tool can convert file system encoded in NFD mode to NFC mode.
 
     Usage:
-      convert-nfd-unicode-filesystem-to-nfc-unicode <path>
-      convert-nfd-unicode-filesystem-to-nfc-unicode <url>
-      convert-nfd-unicode-filesystem-to-nfc-unicode -h | --help | --version
+      nfd2nfc <path>
+      nfd2nfc <url>
+      nfd2nfc -h | --help | --version
 
 
 
 
 ::
 
-    $ convert-nfd-unicode-filesystem-to-nfc-unicode /home/username/myproject/
+    $ nfd2nfc /home/username/myproject/
 
 You can use ssh url syntax to fix unicode on remote host :
 
 ::
 
-    $ convert-nfd-unicode-filesystem-to-nfc-unicode foobar@example.com:2000:/home/foobar/www/
+    $ nfd2nfc ssh://foobar@example.com:2000:/home/foobar/www/
 
 Home page : https://bitbucket.org/harobed/convert-nfd-unicode-filesystem-to-nfc-unicode
 Contact : contact@stephane-klein.info
 from setuptools import setup, find_packages
-import sys, os
+import os, re
 
 here = os.path.abspath(os.path.dirname(__file__))
 
-version = '0.1.0'
+v = open(os.path.join(here, 'src', 'nfd2nfc', '__init__.py'))
+version = re.compile(r".*__version__ = '(.*?)'", re.S).match(v.read()).group(1)
+v.close()
 
 install_requires = [
     'docopt'
 ]
 
-
 setup(
-    name='convert-nfd-unicode-filesystem-to-nfc-unicode',
+    name='nfd2nfc',
     version=version,
     description="Convert Mac OSX NFD unicode filename to NFC unicode",
     classifiers=[
     install_requires=install_requires,
     entry_points={
         'console_scripts': [
-            'convert-nfd-unicode-filesystem-to-nfc-unicode=convertnfdunicodefilesystemtonfcunicode:main'
+            'nfd2nfc=nfd2nfc:main'
         ]
     }
 )

File src/convertnfdunicodefilesystemtonfcunicode/__init__.py

-import os
-import sys
-import unicodedata
-from urlparse import urlparse
-
-from docopt import docopt
-
-here = os.path.abspath(os.path.dirname(__file__))
-
-
-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)
-
-remote_cmd = """
-import os
-import sys
-import unicodedata
-
-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)
-
-if __name__ == '__main__':
-    fix_unicode('''%(path)s''', False)
-"""
-
-
-def main():
-    arguments = docopt(
-"""This tool can convert file system encoded in NFD mode to NFC mode.
-
-On Mac OS X, the filesystem encode file name in NFD unicode
-(http://en.wikipedia.org/wiki/Unicode_normalization#Example).
-On GNU/Linux, by default the filesystem encode file name in NFC unicode
-but it can also contain file encoded in NFD mode.
-You can use this tool to convert NFD to NFC.
-
-Usage:
-  convert-nfd-unicode-filesystem-to-nfc-unicode <path>
-  convert-nfd-unicode-filesystem-to-nfc-unicode <url>
-  convert-nfd-unicode-filesystem-to-nfc-unicode -h | --help | --version
-
-Examples :
-
-Convert on local file system (use it on GNU/Linux, not on Mac OS X) :
-
-    $ convert-nfd-unicode-filesystem-to-nfc-unicode /home/username/myproject/
-
-You can use ssh url syntax to fix unicode on remote host :
-
-    $ convert-nfd-unicode-filesystem-to-nfc-unicode foobar@example.com:2000:/home/foobar/www/
-
-Home page : https://bitbucket.org/harobed/convert-nfd-unicode-filesystem-to-nfc-unicode
-Contact : contact@stephane-klein.info
-""",
-        version='0.1.0'
-    )
-    path = arguments['<path>']
-    if path.startswith('ssh://'):
-        url = urlparse(path)
-        assert url.scheme == 'ssh'
-        host = url.netloc
-        port = 22
-        user = os.getlogin()
-        if ':' in host:
-            host, port = host.split(':')
-
-        if '@' in host:
-            user, host = host.split('@')
-
-        path_tmpfile = os.tempnam()
-        basename_tmpfile = os.path.basename(path_tmpfile)  # NOQA
-        f = open(path_tmpfile, 'w')
-        f.write(remote_cmd % {'path': url.path})
-        f.close()
-        os.system('scp -P %(port)s %(path_tmpfile)s %(user)s@%(host)s:/tmp/' % locals())
-        os.system('ssh -p %(port)s %(user)s@%(host)s python /tmp/%(basename_tmpfile)s' % locals())
-    else:
-        if not os.path.exists(path):
-            sys.exit('Error, folder not found %s' % path)
-
-        fix_unicode(path)

File src/nfd2nfc/__init__.py

+import os
+import sys
+import unicodedata
+from urlparse import urlparse
+
+from docopt import docopt
+
+__version__ = '0.1.0'
+
+here = os.path.abspath(os.path.dirname(__file__))
+
+
+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)
+
+remote_cmd = """
+import os
+import sys
+import unicodedata
+
+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)
+
+if __name__ == '__main__':
+    fix_unicode('''%(path)s''', False)
+"""
+
+
+def main():
+    arguments = docopt(
+"""This tool can convert file system encoded in NFD mode to NFC mode.
+
+On Mac OS X, the filesystem encode file name in NFD unicode
+(http://en.wikipedia.org/wiki/Unicode_normalization#Example).
+On GNU/Linux, by default the filesystem encode file name in NFC unicode
+but it can also contain file encoded in NFD mode.
+You can use this tool to convert NFD to NFC.
+
+Usage:
+  nfd2nfc <path>
+  nfd2nfc <url>
+  nfd2nfc -h | --help | --version
+
+Examples :
+
+Convert on local file system (use it on GNU/Linux, not on Mac OS X) :
+
+    $ nfd2nfc /home/username/myproject/
+
+You can use ssh url syntax to fix unicode on remote host :
+
+    $ nfd2nfc ssh://foobar@example.com:2000:/home/foobar/www/
+
+Home page : https://bitbucket.org/harobed/convert-nfd-unicode-filesystem-to-nfc-unicode
+Contact : contact@stephane-klein.info
+""",
+        version=__version__
+    )
+    path = arguments['<path>']
+    if path.startswith('ssh://'):
+        url = urlparse(path)
+        assert url.scheme == 'ssh'
+        host = url.netloc
+        port = 22
+        user = os.getlogin()
+        if ':' in host:
+            host, port = host.split(':')
+
+        if '@' in host:
+            user, host = host.split('@')
+
+        path_tmpfile = os.tempnam()
+        basename_tmpfile = os.path.basename(path_tmpfile)  # NOQA
+        f = open(path_tmpfile, 'w')
+        f.write(remote_cmd % {'path': url.path})
+        f.close()
+        os.system('scp -P %(port)s %(path_tmpfile)s %(user)s@%(host)s:/tmp/' % locals())
+        os.system('ssh -p %(port)s %(user)s@%(host)s python /tmp/%(basename_tmpfile)s' % locals())
+        os.system('ssh -p %(port)s %(user)s@%(host)s rm /tmp/%(basename_tmpfile)s' % locals())
+    else:
+        if not os.path.exists(path):
+            sys.exit('Error, folder not found %s' % path)
+
+        fix_unicode(path)