changeset 6231:f6a9e8dd7d37

Implement a post-download hook for code repositories. Use the post-download hook to obtain the LilyPond version from the VERSION file as before, but only after we have successfully cloned the git repository. Fixes issue 4: git download assumes dir already exists https://github.com/janneke/gub/issues/4
author Julien Rioux <julien.rioux@gmail.com>
date Tue, 03 Sep 2013 19:48:50 +0200
parents bfe4b61a654e
children 692b2b39fc49
files gub/repository.py gub/specs/lilypond.py
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gub/repository.py	Mon Jul 08 12:35:23 2013 +0100
+++ b/gub/repository.py	Tue Sep 03 19:48:50 2013 +0200
@@ -237,6 +237,8 @@
         return os.path.splitext (os.path.basename (self.source))[0]
     def download (self):
         pass
+    def post_download_hook (self):
+        pass
     def checksum (self):
         '''A checksum that characterizes the entire repository.
 
@@ -355,6 +357,7 @@
         else:
             dir = self.dir
             self.system ('darcs get %(source)s %(dir)s' % locals ())
+        self.post_download_hook ()
         
     def is_tracking (self):
         return True
@@ -449,6 +452,7 @@
         if self.is_downloaded ():
             return
         self.download_url (self.source, self.dir)
+        self.post_download_hook ()
 
     def checksum (self):
         return misc.ball_basename (self._file_name ())
@@ -644,6 +648,7 @@
         if self.branch and not (self.revision and self.is_downloaded ()):
             self.git ('fetch %(source)s %(branch)s:refs/heads/%(url_host)s/%(url_dir)s/%(branch)s' % self.__dict__)
         self.checksums = {}
+        self.post_download_hook ()
     def get_ref (self):
         if not self.revision:
             return self.branch_dir ().replace ('//', '/')
@@ -849,6 +854,7 @@
 
         open (dir + '/.vc-checksum', 'w').write (cs)
         open (dir + '/.vc-timestamp', 'w').write ('%d' % stamp)
+        self.post_download_hook ()
         
     def cvs_dirs (self, branch_dir):
         retval =  []
@@ -917,6 +923,7 @@
             self._checkout ()
         elif self._current_revision () != self.revision:
             self._update (self.revision)
+        self.post_download_hook ()
         self.info ('downloaded version: ' + self.version ())
 
     def _copy_working_dir (self, dir, copy):
--- a/gub/specs/lilypond.py	Mon Jul 08 12:35:23 2013 +0100
+++ b/gub/specs/lilypond.py	Tue Sep 03 19:48:50 2013 +0200
@@ -75,6 +75,10 @@
             'VERSION', 'MAJOR_VERSION',
             '%(MAJOR_VERSION)s.%(MINOR_VERSION)s.%(PATCH_LEVEL)s')
 
+    @staticmethod
+    def post_download_hook (self):
+        self.version = misc.bind_method (LilyPond.version_from_VERSION, self)
+
     def __init__ (self, settings, source):
         target.AutoBuild.__init__ (self, settings, source)
         # FIXME: should add to C_INCLUDE_PATH
@@ -85,7 +89,10 @@
                                  + ' -I%(builddir)s' % locals ()
                                  + ' -I%(srcdir)s/lily/out' % locals ())
         if isinstance (source, repository.Git):
-            source.version = misc.bind_method (LilyPond.version_from_VERSION, source)
+            if source.is_downloaded ():
+                source.version = misc.bind_method (LilyPond.version_from_VERSION, source)
+            else:
+                source.post_download_hook = misc.bind_method (LilyPond.post_download_hook, source)
         if 'stat' in misc.librestrict () and not 'tools::texlive' in self.dependencies:
             build.append_dict (self, {'PATH': os.environ['PATH']}) # need mf, mpost from system
     def get_conflict_dict (self):