Henrik Tunedal avatar Henrik Tunedal committed 9ea7bf0

Fixed downloading, which I accidentally broke earlier.

Comments (0)

Files changed (1)

     filename = os.path.join(metadata_root, package_id) + ".txt"
     return os.path.exists(filename)
 
+def has_source(package_id):
+    return (valid_id(package_id) and
+            os.path.isdir(os.path.join(source_root, package_id)))
+
 # Duplicate even more functionality, this time from build.py
 def clone_repo(metadata):
     if not os.path.exists(source_root):
 # Try to download source for all packages
 def clone_everything(packages=None):
     done = []
+    skipped = []
     failed = []
     if packages:
         metadata_files = [p + ".txt" for p in packages]
     else:
-        metadata_files = os.path.listdir(metadata_root)
+        metadata_files = os.listdir(metadata_root)
     try:
         for package in metadata_files:
             package_dir = os.path.join(metadata_root, package)
             metadata = parse_package_metadata(package_dir)
             print metadata["package id"]
-            try:
-                clone_repo(metadata)
-                done.append(metadata)
-                print "Done."
-            except VCSError:
-                failed.append(metadata)
-                print "Failed."
+            if not has_source(metadata["package id"]):
+                try:
+                    clone_repo(metadata)
+                    done.append(metadata)
+                    print "Done."
+                except VCSError:
+                    failed.append(metadata)
+                    print "Failed."
+            else:
+                skipped.append(metadata)
+                print "Skipped."
             print
     except KeyboardInterrupt:
         print
         print "Keyboard interrupt => aborting"
-    print "Cloned %i packages:" % len(done)
-    for p in done: print "  ", p["package id"]
-    print "Failed to clone %i packages:" % len(failed)
-    for p in failed: print "  ", p["package id"]
+    for text, cat in [("Skipped", skipped),
+                      ("Failed to clone", failed),
+                      ("Cloned", done)]:
+        if len(cat):
+            print "%s %i packages:" % (text, len(cat))
+            for p in cat: print "  " + p["package id"]
+            print
+    print "%i skipped, %i failed, %i cloned" \
+        % tuple([len(l) for l in (skipped, failed, done)])
 
 
 ################################################
 
 def main():
     packages = [interpret_package_name(p) for p in args.packages]
+    if args.update:
+        raise NotImplementedError, "updates not implemented yet"
+        update_sources(packages)
     if args.download:
         clone_everything(packages)
-    elif args.list:
+    if args.list and not (args.update or args.download):
         license_type = args.list.lower()
         for package in (packages or os.listdir(source_root)):
             meta = metadata_for_id(package)
                 continue
             for fil in results[key]:
                 print fil
-    else:
+    elif not (args.update or args.download):
         for package in (packages or os.listdir(source_root)):
             meta = metadata_for_id(package)
             print "%s (%s)" % (meta["package id"], meta["license"])
     parser.add_argument('-a', "--apps", action="store_true",
                         help='only process application directories')
     parser.add_argument('-d', "--download", action="store_true",
-                        help='download application sources')
+                        help='download new application sources')
+    parser.add_argument('-u', "--update", action="store_true",
+                        help='update application sources')
     parser.add_argument('-l', "--list", action="store", metavar="LICENSE",
                         help='list files with the specified license')
     parser.add_argument("packages", nargs="*", metavar="PACKAGE",
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.