Stéphane Klein avatar Stéphane Klein committed 1b52bec

Append remote feature

Comments (0)

Files changed (2)

+[pep8]
+ignore=E401
+max-line-length=140
+ignore=E122

src/convertnfdunicodefilesystemtonfcunicode/__init__.py

 import os
 import sys
 import unicodedata
+from urlparse import urlparse
+from uuid import uuid4
 
 from docopt import docopt
 
             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(
 """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
 
+You can use ssh url syntax to fix unicode on remote host, example :
+
+    $ convert-nfd-unicode-filesystem-to-nfc-unicode foobar@example.com:2000:/home/foobar/www/
+
 """,
         version='0.1.0'
     )
     path = arguments['<path>']
-    if not os.path.exists(path):
-        sys.exit('Error, folder not found %s' % 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(':')
 
-    fix_unicode(path)
+        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()
+        print('scp -P %(port)s %(path_tmpfile)s %(user)s@%(host)s/tmp/' % locals())
+        os.system('scp -P %(port)s %(path_tmpfile)s %(user)s@%(host)s:/tmp/' % locals())
+        print('ssh -p %(port)s %(user)s@%(host)s python /tmp/%(basename_tmpfile)s' % 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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.