[Sugar-devel] [PATCH] Bundlebuilder: don't fail to package if git is not installed, OLPC #11341

from = Simon Schampijer simon at schampijer.de
Thu Nov 10 03:44:34 EST 2011


From: Simon Schampijer <simon at schampijer.de>

When git is installed, it will return non-zero if it gets asked to list
the files in a non-git-repository. The subprocess.Popen instantiation is
successful in this case and the returncode attribute will contain the
error code from git. The current code handles this fine and does fall
back to our own source file listing facility.

If git isn't installed, however, trying to instantiate subprocess.Popen
will fail with OSError. We need to catch this and fall back to our own
source file listing facility like we do for the non-repository case.

Signed-off-by: Simon Schampijer <simon at laptop.org>
---
 src/sugar/activity/bundlebuilder.py |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/sugar/activity/bundlebuilder.py b/src/sugar/activity/bundlebuilder.py
index e7641bb..7405fcf 100644
--- a/src/sugar/activity/bundlebuilder.py
+++ b/src/sugar/activity/bundlebuilder.py
@@ -184,11 +184,19 @@ class XOPackager(Packager):
         bundle_zip.close()
 
     def _get_files_in_git(self):
-        git_ls = subprocess.Popen(['git', 'ls-files'], stdout=subprocess.PIPE,
-                                  cwd=self.config.source_dir)
+        try:
+            git_ls = subprocess.Popen(['git', 'ls-files'],
+                                      stdout=subprocess.PIPE,
+                                      cwd=self.config.source_dir)
+        except OSError:
+            logging.warn('XOPackager, git is not installed, ' \
+                             'fall back to filtered list')
+            return list_files(self.config.source_dir,
+                              IGNORE_DIRS, IGNORE_FILES)
         stdout, _ = git_ls.communicate()
         if git_ls.returncode:
-            # Fall back to filtered list
+            logging.warn('XOPackager, this is not a git repository, ' \
+                             'fall back to filtered list')
             return list_files(self.config.source_dir,
                               IGNORE_DIRS, IGNORE_FILES)
 
@@ -204,11 +212,19 @@ class SourcePackager(Packager):
                                          self.config.tar_name)
 
     def get_files(self):
-        git_ls = subprocess.Popen(['git', 'ls-files'], stdout=subprocess.PIPE,
-                                  cwd=self.config.source_dir)
+        try:
+            git_ls = subprocess.Popen(['git', 'ls-files'],
+                                      stdout=subprocess.PIPE,
+                                      cwd=self.config.source_dir)
+        except OSError:
+            logging.warn('SourcePackager, git is not installed, ' \
+                             'fall back to filtered list')
+            return list_files(self.config.source_dir,
+                              IGNORE_DIRS, IGNORE_FILES)
         stdout, _ = git_ls.communicate()
         if git_ls.returncode:
-            # Fall back to filtered list
+            logging.warn('SourcePackager, this is not a git repository, ' \
+                             'fall back to filtered list')
             return list_files(self.config.source_dir,
                               IGNORE_DIRS, IGNORE_FILES)
 
-- 
1.7.7



More information about the Sugar-devel mailing list