[pony-build] pony-build Cache Dir

C. Titus Brown ctb at msu.edu
Sun Jan 24 14:51:17 PST 2010


On Sat, Jan 23, 2010 at 08:21:57PM -0400, Max Laite wrote:
> Pushed my work to mkdir branch under my repo.  Probably not the prettiest
> code, but it works......Would like to discuss with you tomorrow(Jan. 24) if
> possible.
> 
> It still has some stuff in it I was using for debugging, but that is what i
> got so far. I am sort of tied to weekends for working on pb with my school
> and work load. Hoping to pick up my pace after i get settled into the
> semester though.

Hi Max, thanks! I've attached the diff of your work for everyone's reference.

Miscellaneous comments and questions:

 - the code to create the actual cache parent dir, ~/.pony-build/, should
   probably be factored out into a separate function in the pony_client
   module, because it will be used by a bunch of classes -- including
   GitClone, HgCheckout, and SvCheckout.

 - how have you tested this?  i.e. what test conditions did you use?

   I wrote a short test script, available in my repo under branch 'mkdir',
   'client/test-git':

      http://github.com/ctb/pony-build/blob/mkdir/client/test-git

   If you want, you could add some additional scripts or test commands
   to test other cases than I did.

 - Check out PEP 8 re code style; in particular, you should be putting
   spaces between '#' and your comment.  I know, nitpicky... 

     http://www.python.org/dev/peps/pep-0008/

Overall, looks good! Could you outline what additional things you think need to
be done?

thanks,
--titus
-- 
C. Titus Brown, ctb at msu.edu
-------------- next part --------------
diff --git a/client/pony_client.py b/client/pony_client.py
index 49e5c7e..8591acb 100644
--- a/client/pony_client.py
+++ b/client/pony_client.py
@@ -358,13 +358,20 @@ class GitClone(SetupCommand):
         if self.use_cache:
             cache_dir = self.cache_dir
             if not cache_dir:
-                cache_dir = guess_cache_dir(dirname)
-
+		#setup some variables for cache folder locations
+                tmp_cache_dir = guess_cache_dir(dirname)
+		cache_dir = tmp_cache_dir
+		packlen = len(dirname)
+		#trim the pckg name so can create the cache_dir and not the repo dir
+		cache_dir = cache_dir[:-packlen]
+		print 'cache_dir is: ' + cache_dir
+		print 'repo cache is: ' + tmp_cache_dir
         ##
 
-        if self.use_cache and cache_dir:
+        if self.use_cache and os.path.exists(tmp_cache_dir):
             cwd = os.getcwd()
-            os.chdir(cache_dir)
+            os.chdir(tmp_cache_dir)
+	    print 'changed to: ' + tmp_cache_dir + ' to do fetch.'
             branchspec = '%s:%s' % (self.branch, self.branch)
             cmdlist = ['git', 'fetch', '-ufv', self.repository, branchspec]
             (ret, out, err) = _run_command(cmdlist)
@@ -377,24 +384,40 @@ class GitClone(SetupCommand):
                 return
 
             os.chdir(cwd)
-
+	else:
+	    if not os.path.isdir(cache_dir):
+		cwd = os.getcwd()
+            	# if ~/.pony-build doesnt exist, create it, then change to it and do a initial clone
+		print 'trying: ' + cache_dir
+                os.mkdir(cache_dir)
+                os.chdir(cache_dir)
+                print 'had to make a new cache_dir: ' + cache_dir
+                cmdlist = ['git', 'clone', self.repository]
+                (ret, out, err) = _run_command(cmdlist)
+		os.chdir(cwd)
+            else:
+		cwd = os.getcwd()
+		# if cache_dir already exists, just do a clone to create the repo
+                print 'changing to: ' + cache_dir + ' to make new repo dir'
+                os.chdir(cache_dir)
+                cmdlist = ['git', 'clone', self.repository]
+	        (ret, out, err) = _run_command(cmdlist)
+		os.chdir(cwd)
         ##
-
         print cmdlist, out
 
         # now, do a clone, from either the parent OR the local cache
         location = self.repository
-        if cache_dir:
-            location = cache_dir
-
-        cmdlist = ['git', 'clone', self.repository]
+        if tmp_cache_dir:
+            location = tmp_cache_dir
+       	cmdlist = ['git', 'clone', location]
         (ret, out, err) = _run_command(cmdlist)
 
-        self.results_dict['clone'] = \
-                 dict(status=ret, output=out, errout=err,
-                      command=str(cmdlist))
-        if ret != 0:
-            return
+       	self.results_dict['clone'] = \
+               	 dict(status=ret, output=out, errout=err,
+                    	command=str(cmdlist))
+       	if ret != 0:
+               	return
 
         print cmdlist, out
 


More information about the pony-build mailing list