remove checking packaging dir in export module, fix #635
authorZhang Qiang <qiang.z.zhang@intel.com>
Mon, 7 Jan 2013 05:30:55 +0000 (13:30 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Mon, 7 Jan 2013 06:20:06 +0000 (14:20 +0800)
packaging dir will be checked while guessing spec file.

Change-Id: I31409b41372018637bbf1bba608dfff84805ebe9

gitbuildsys/cmd_export.py
gitbuildsys/utils.py

index b65fba5531bc2abdd07149c1a10cf3fa8ab34c84..3305589a0fddbef4af4670760a57b1f7a9ae3480 100644 (file)
@@ -231,10 +231,6 @@ def main(args):
     utils.git_status_checker(repo, args)
     workdir = repo.path
 
-    packaging_dir = get_packaging_dir(args)
-    if not os.path.exists(os.path.join(workdir, packaging_dir)):
-        raise GbsError("No packaging directory '%s/', so there is nothing to "
-                       "export." % packaging_dir)
 
     # Only guess spec filename here, parse later when we have the correct
     # spec file at hand
@@ -244,6 +240,7 @@ def main(args):
         commit = 'WC.UNTRACKED'
     else:
         commit = 'HEAD'
+    packaging_dir = get_packaging_dir(args)
     relative_spec = utils.guess_spec(workdir, packaging_dir, args.spec, commit)
 
     if args.outdir:
index ca2467af784e2e72de2edb51b7546c58aabe8fc9..4ad0982842f6bcc9fb58e88bc3c32d216c5e53c8 100644 (file)
@@ -61,15 +61,20 @@ def guess_spec(git_path, packaging_dir, given_spec, commit_id='WC.UNTRACKED'):
     git_path = os.path.abspath(git_path)
 
     if commit_id == 'WC.UNTRACKED':
-        check = lambda fname: os.path.exists(os.path.join(git_path, fname))
+        check = lambda fname, dir_only=False: os.path.exists(os.path.join( \
+                       git_path, fname))
         glob_ = lambda pattern: [ name.replace(git_path+'/', '')
             for name in glob.glob(os.path.join(git_path, pattern)) ]
         msg = 'No such spec file %s'
     else:
-        check = lambda fname: file_exists_in_rev(git_path, fname, commit_id)
+        check = lambda fname, dir_only=False : file_exists_in_rev(git_path, \
+                       fname, commit_id, dir_only=dir_only)
         glob_ = lambda pattern: glob_in_rev(git_path, pattern, commit_id)
         msg = "No such spec file %%s in %s" % commit_id
 
+    if not check(packaging_dir, True):
+        raise GbsError("No packaging directory: '%s/', so there is nothing to "
+                       "export." % packaging_dir)
     if given_spec:
         spec = os.path.join(packaging_dir, given_spec)
         if not check(spec):
@@ -489,10 +494,13 @@ def show_file_from_rev(git_path, relative_path, commit_id):
     return None
 
 
-def file_exists_in_rev(git_path, relative_path, commit_id):
+def file_exists_in_rev(git_path, relative_path, commit_id, dir_only=False):
     """Check if file exists in given given revision."""
-    cmd = 'cd %s; git ls-tree --name-only %s %s' % (
-        git_path, commit_id, relative_path)
+    git_opts = ['--name-only']
+    if dir_only:
+       git_opts += ['-d']
+    cmd = 'cd %s; git ls-tree %s %s %s' % (
+        git_path, ' '.join(git_opts), commit_id, relative_path)
 
     try:
         output = subprocess.check_output(cmd, shell=True)