From 1c8693acbd5bad0d86bc026eb4acf6daeb8896b1 Mon Sep 17 00:00:00 2001 From: Zhang Qiang Date: Mon, 7 Jan 2013 13:30:55 +0800 Subject: [PATCH] remove checking packaging dir in export module, fix #635 packaging dir will be checked while guessing spec file. Change-Id: I31409b41372018637bbf1bba608dfff84805ebe9 --- gitbuildsys/cmd_export.py | 5 +---- gitbuildsys/utils.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gitbuildsys/cmd_export.py b/gitbuildsys/cmd_export.py index b65fba5..3305589 100644 --- a/gitbuildsys/cmd_export.py +++ b/gitbuildsys/cmd_export.py @@ -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: diff --git a/gitbuildsys/utils.py b/gitbuildsys/utils.py index ca2467a..4ad0982 100644 --- a/gitbuildsys/utils.py +++ b/gitbuildsys/utils.py @@ -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) -- 2.7.4