damned-lies r1507 - in trunk: . stats stats/management/commands



Author: claudep
Date: Sat Mar 21 11:11:47 2009
New Revision: 1507
URL: http://svn.gnome.org/viewvc/damned-lies?rev=1507&view=rev

Log:
2009-03-21  Claude Paroz  <claude 2xlibre net>

	* stats/management/commands/migrate-to-git.py: New script in prevision to
	git migration in April.
	* stats/models.py: branch is considered new if checkout folder does not
	exist.

Added:
   trunk/stats/management/commands/migrate-to-git.py   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/stats/models.py

Added: trunk/stats/management/commands/migrate-to-git.py
==============================================================================
--- (empty file)
+++ trunk/stats/management/commands/migrate-to-git.py	Sat Mar 21 11:11:47 2009
@@ -0,0 +1,50 @@
+import os
+import shutil
+from django.core.management.base import BaseCommand
+from stats.models import Module, Branch
+from stats import utils
+
+class Command(BaseCommand):
+
+    def handle(self, *args, **options):
+        """ Migrate GNOME SVN modules to git repos in bulk """
+        if len(args) == 1:
+            modules = [Module.objects.get(name = args[0])]
+        else:
+            modules = Module.objects.filter(vcs_root='http://svn.gnome.org/svn')
+        for module in modules:
+            old_branch_dirs = []
+            for branch in module.branch_set.all():
+                old_branch_dirs.append(branch.co_path())
+            
+            module.vcs_type = "git"
+            module.vcs_root = "git://git.gnome.org/%s" % module.name
+            module.vcs_web = "http://git.gnome.org/cgit/%s/"; % module.name
+            module.save()
+            
+            # Checkout new git repo with master branch
+            head_branch = Branch.objects.get(module__name=module.name, name='HEAD')
+            head_branch.name = "master"
+            try:
+                head_branch.save() # Save will do a checkout
+            except Exception, e:
+                print "Unable to save master branch for module '%s': %s" % (module.name, e)
+                continue
+            
+            for branch in module.branch_set.exclude(name='master'):
+                # Checkout branch (other than master)
+                cmd = "cd \"%(localdir)s\" && git checkout --track -b %(branch)s  origin/%(branch)s" % {
+                        "localdir" : branch.co_path(),
+                        "branch" : branch.name,
+                        }
+                try:
+                    utils.run_shell_command(cmd, raise_on_error=True)
+                except Exception, e:
+                    print "Unable to checkout branch '%s' of module '%s': %s" % (branch.name, module.name, e)
+                    continue
+                branch.update_stats(force=False)
+                
+            # delete old checkouts
+            for branch_dir in old_branch_dirs:
+                shutil.rmtree(branch_dir)
+

Modified: trunk/stats/models.py
==============================================================================
--- trunk/stats/models.py	(original)
+++ trunk/stats/models.py	Sat Mar 21 11:11:47 2009
@@ -411,7 +411,7 @@
         localroot = os.path.join(settings.SCRATCHDIR, vcs_type)
         if vcs_type in ('hg', 'git'):
             moduledir = self.module.name
-            branch_exists = self.id != None
+            branch_exists = self.id != None and os.access(self.co_path(), os.X_OK | os.W_OK)
         else:
             moduledir = self.module.name + "." + self.name
             branch_exists = os.access(self.co_path(), os.X_OK | os.W_OK)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]