From: Simon Schampijer <si...@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 <si...@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

_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to