[mirrorbrain-commits] [opensuse-svn] r6961 - trunk/tools/download-redirector-v2/mirrordoctor

From: Novell Forge SVN <noreply_at_novell.com>
Date: Mon, 30 Mar 2009 18:05:42 -0600 (MDT)
Author: poeml
Date: 2009-03-30 18:05:40 -0600 (Mon, 30 Mar 2009)
New Revision: 6961

Modified:
   trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py
Log:
mb export:
- implement a new output format, named "vcs".
  This format generates a file tree which can be imported/committed into
  a version control system (VCS). This can be used to periodically dump
  the database into a working copy of such a repository and commit the
  changes, making use of the commit mail mechanism of the VCS to send
  change notifications.
  You need to specify --target-dir=PATH.
  If you use the --commit=VCS option, "VCS commit" will be run after the
  export on the directory.


Modified: trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py
===================================================================
--- trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py	2009-03-30 22:28:26 UTC (rev 6960)
+++ trunk/tools/download-redirector-v2/mirrordoctor/mirrordoctor.py	2009-03-31 00:05:40 UTC (rev 6961)
@@ -908,27 +908,47 @@
 
 
 
-    @cmdln.option('--format', metavar='FORMAT',
-            help='Specify the output format: [django|postgresql]')
     @cmdln.option('--project', metavar='PROJECT',
                   help='Specify a project name (previously corresponding to a MirrorBrain instance).')
+    @cmdln.option('--commit', metavar='VCS',
+                  help='run "VCS commit" on the directory specified via --target-dir')
+    @cmdln.option('--target-dir', metavar='PATH',
+                  help='For the "vcs" output format, specify a target directory to place files into')
+    @cmdln.option('--format', metavar='FORMAT',
+            help='Specify the output format: [django|postgresql|vcs]')
     def do_export(self, subcmd, opts, *args):
         """${cmd_name}: export the mirror list as text file
 
-        Output format is suitable to be used in a Django ORM.
+        There are different output formats:
 
+        Format "django" is suitable to be used in a Django ORM.
+
+        Format "postgresql" is suitable to be imported into a PostgreSQL
+        database.
+
+        Format "vcs" generates a file tree which can be imported/committed into
+        a version control system (VCS). This can be used to periodically dump
+        the database into a working copy of such a repository and commit the
+        changes, making use of the commit mail mechanism of the VCS to send
+        change notifications.
+        You need to specify --target-dir=PATH for this. 
+        If you use the --commit=VCS option, "VCS commit" will be run after the
+        export on the directory.
+
         ${cmd_usage}
         ${cmd_option_list}
         """
 
         import mb.exports
 
+        if not opts.format:
+            sys.exit('You need to specify an output format. See --help output.')
+
         if opts.format == 'django' and not opts.project:
             sys.exit('For Django ORM format, specify a project name (roughly corresponding to a MirrorBrain instance) name with --project')
+        if opts.format == 'vcs' and not opts.target_dir:
+            sys.exit('To export for a version control system, specify a target directory')
 
-        if not opts.format:
-            sys.exit('You need to specify an output format. See --help output.')
-
         if opts.format == 'django':
             print mb.exports.django_header
 
@@ -938,16 +958,22 @@
         elif opts.format == 'postgresql':
             print mb.exports.postgresql_header
 
+        elif opts.format == 'vcs':
+            import os, os.path
+            if not os.path.exists(opts.target_dir):
+                os.makedirs(opts.target_dir, 0750)
+            os.chdir(opts.target_dir)
+
         else:
             sys.exit('unknown format %r' % opts.format)
 
 
         mirrors = self.conn.Server.select()
-        for i in mirrors:
-            if i.comment == None:
-                #print 'null comment', i
-                i.comment = ''
-            d = mb.conn.server2dict(i)
+        for m in mirrors:
+            if m.comment == None:
+                #print 'null comment', m
+                m.comment = ''
+            d = mb.conn.server2dict(m)
             d.update(dict(project=opts.project))
 
             #print >>sys.stderr, d
@@ -961,10 +987,19 @@
 
             if opts.format == 'django':
                 print mb.exports.django_template % d
+
             elif opts.format == 'postgresql':
                 print mb.exports.postgresql_template % d
 
+            elif opts.format == 'vcs':
+                s = mb.conn.server_show_template % mb.conn.server2dict(m)
+                s = '\n'.join([ i for i in s.splitlines() if not i.startswith('statusBaseurl') ]) + '\n'
+                open(m.identifier, 'w').write(s)
 
+        if opts.format == 'vcs' and opts.commit:
+            os.system('%s commit -m "autocommit by mb" %s > /dev/null' \
+                        % (opts.commit, opts.target_dir))
+
 if __name__ == '__main__':
     import sys
     mirrordoctor = MirrorDoctor()

_______________________________________________
Opensuse-svn mailing list
Opensuse-svn_at_forge.novell.com
http://forge.novell.com/mailman/listinfo/opensuse-svn


_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on 2009-03-31Z00:06:48

This archive was generated by hypermail 2.2.0 : 2009-07-10Z19:18:12 GMT