Finish script

The script should now correctly be able to sync Settings.

TODO:
  - Add support for multiple projects
  - Add support for multiple CAF files in one project
diff --git a/cm_sync.py b/cm_sync.py
index b81534d..37fdfda 100755
--- a/cm_sync.py
+++ b/cm_sync.py
@@ -1,21 +1,6 @@
 #!/usr/bin/python2
 
 from xml.dom import minidom
-from subprocess import check_output
-
-#print('Welcome to the CyanogenMod Crowdin synchronization script')
-#print('---------------------------------------------------------\n')
-
-# Execute normal Crowdin sync
-#print('---------------------------------------------------------')
-#print('Executing normal Crowdin synchronization.................')
-#print(check_output(["java", "-jar", "crowdin-cli.jar", "upload", "sources"]))
-#print('Normal Crowdin synchronization complete..................')
-#print('---------------------------------------------------------\n')
-
-# Execute CAF search
-#print('---------------------------------------------------------')
-#print('Executing CAF search.....................................')
 
 def create_cm_caf_xml(strings_base, strings_cm, path):
     # Load AOSP file and resources
@@ -71,7 +56,6 @@
                 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
                 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
                 t = 4
-            print('found string: ' + z)
             f.write(list_cm_string[names_cm_string.index(z)].toxml() + '\n')
     for z in names_cm_string_array:
         if not z in names_base_string_array:
@@ -80,7 +64,6 @@
                 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
                 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
                 t = 4
-            print('found string array: ' + z)
             f.write(list_cm_string_array[names_cm_string_array.index(z)].toxml() + '\n')
     for z in names_cm_plurals:
         if not z in names_base_plurals:
@@ -89,28 +72,8 @@
                 f.write('<?xml version="1.0" encoding="utf-8"?>\n')
                 f.write('<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">\n')
                 t = 4
-            print('found plurals: ' + z)
             f.write(list_cm_plurals[names_cm_plurals.index(z)].toxml() + '\n')
 
     if t == 4:
         f.write('</resources>')
         f.close()
-
-#print('Executing CAF search.....................................')
-#print('CAF search complete......................................')
-#print('---------------------------------------------------------\n')
-
-# Cleanup
-#print('---------------------------------------------------------')
-#print('Executing cleanup........................................')
-#print('Cleanup complete.........................................')
-#print('---------------------------------------------------------\n')
-
-# Committing
-#print('---------------------------------------------------------')
-#print('Executing commit.........................................')
-#print('Commit complete..........................................')
-#print('---------------------------------------------------------\n')
-
-# Done
-#print('Script is done. Goodbye!')
diff --git a/test.py b/test.py
index 6472b4c..17444a0 100755
--- a/test.py
+++ b/test.py
@@ -4,8 +4,10 @@
 import sys
 import cm_sync
 from urllib import urlretrieve
-from subprocess import call
+from subprocess import call, check_output
 from xml.dom import minidom
+import mmap
+import git
 
 print('STEP 0: Welcome to the CM Crowdin sync script\n')
 
@@ -29,12 +31,35 @@
         urlretrieve(url, path_to_base)
         cm_sync.create_cm_caf_xml(path_to_base, path_to_cm, path)
         cm_caf.append(path + '/cm_caf.xml')
+        print('Created ' + path + '/cm_caf.xml')
 
-print('\nSTEP 2: Upload Crowdin source translations')
+#print('\nSTEP 2: Upload Crowdin source translations')
+#print(check_output(["java", "-jar", "crowdin-cli.jar", "upload", "sources"]))
 
-print('\nSTEP 3: Clean up')
+#print('STEP 3: Download Crowdin translations')
+#print(check_output(["java", "-jar", "crowdin-cli.jar", "download"]))
+
+print('STEP 4A: Clean up of empty translations')
+# Search for all XML files
+result = [os.path.join(dp, f) for dp, dn, filenames in os.walk(os.getcwd()) for f in filenames if os.path.splitext(f)[1] == '.xml']
+for xml_file in result:
+    if '<resources/>' in open(xml_file).read():
+        print ('Removing ' + xml_file)
+        os.remove(xml_file)
+    if '<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"/>' in open(xml_file).read():
+        print ('Removing ' + xml_file)
+        os.remove(xml_file)    
+
+print('\nSTEP 4B: Clean up of source cm_caf.xmls')
 for cm_caf_file in cm_caf:
     print ('Removing ' + cm_caf_file)
     os.remove(cm_caf_file)
 
-print('\nSTEP 4: Done!')
+print('\nSTEP 5: Push translations to Git')
+path_repo = os.getcwd() + '/packages/apps/Settings'
+repo = git.Repo(path_repo)
+print repo.git.add(path_repo)
+print repo.git.commit(m='Automatic translations import')
+print repo.git.push('ssh://cobjeM@review.cyanogenmod.org:29418/CyanogenMod/android_packages_apps_Settings', 'HEAD:refs/for/cm-11.0')
+
+print('\nSTEP 6: Done!')