summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndoni Morales Alastruey <ylatuya@gmail.com>2013-07-12 19:00:50 +0200
committerAndoni Morales Alastruey <ylatuya@gmail.com>2013-07-12 19:10:48 +0200
commitd73bb720cdaa51e1a95fa4cc1011df196e4821a2 (patch)
tree65d5466f7913dfec8d39bd09c5be4efbf9efd69c
parentb0d467ff2b0af51a2d6bbe603e252072a029c6b9 (diff)
build: add a --dry-run option that only prints commands
This is useful to reproduce a build in the shell. Modified environment variables by recipes using new_env and append_env are not yet exposed correctly
-rw-r--r--cerbero/build/oven.py3
-rw-r--r--cerbero/commands/build.py12
-rw-r--r--cerbero/utils/shell.py17
3 files changed, 22 insertions, 10 deletions
diff --git a/cerbero/build/oven.py b/cerbero/build/oven.py
index b73c48a..a76582a 100644
--- a/cerbero/build/oven.py
+++ b/cerbero/build/oven.py
@@ -45,7 +45,7 @@ class Oven (object):
STEP_TPL = '[(%s/%s) %s -> %s ]'
def __init__(self, recipes, cookbook, force=False, no_deps=False,
- missing_files=False):
+ missing_files=False, dry_run=False):
if isinstance(recipes, Recipe):
recipes = [recipes]
self.recipes = recipes
@@ -53,6 +53,7 @@ class Oven (object):
self.force = force
self.no_deps = no_deps
self.missing_files = missing_files
+ shell.DRY_RUN = dry_run
def start_cooking(self):
'''
diff --git a/cerbero/commands/build.py b/cerbero/commands/build.py
index 3ea9ffa..a0c62f9 100644
--- a/cerbero/commands/build.py
+++ b/cerbero/commands/build.py
@@ -35,7 +35,10 @@ class Build(Command):
ArgparseArgument('--missing-files', action='store_true',
default=False,
help=_('prints a list of files installed that are '
- 'listed in the recipe'))]
+ 'listed in the recipe')),
+ ArgparseArgument('--dry-run', action='store_true',
+ default=False,
+ help=_('only print commands instead of running them '))]
if force is None:
args.append(
ArgparseArgument('--force', action='store_true',
@@ -58,15 +61,16 @@ class Build(Command):
if self.no_deps is None:
self.no_deps = args.no_deps
self.runargs(config, args.recipe, args.missing_files, self.force,
- self.no_deps)
+ self.no_deps, dry_run=args.dry_run)
def runargs(self, config, recipes, missing_files=False, force=False,
- no_deps=False, cookbook=None):
+ no_deps=False, cookbook=None, dry_run=False):
if cookbook is None:
cookbook = CookBook(config)
oven = Oven(recipes, cookbook, force=self.force,
- no_deps=self.no_deps, missing_files=missing_files)
+ no_deps=self.no_deps, missing_files=missing_files,
+ dry_run=dry_run)
oven.start_cooking()
diff --git a/cerbero/utils/shell.py b/cerbero/utils/shell.py
index 8e23216..46e3240 100644
--- a/cerbero/utils/shell.py
+++ b/cerbero/utils/shell.py
@@ -30,6 +30,7 @@ import shutil
from cerbero.enums import Platform
from cerbero.utils import _, system_info, to_unixpath
+from cerbero.utils import messages as m
from cerbero.errors import FatalError
@@ -39,6 +40,7 @@ TAR = 'tar'
PLATFORM = system_info()[0]
LOGFILE = None # open('/tmp/cerbero.log', 'w+')
+DRY_RUN = False
class StdOut:
@@ -76,7 +78,7 @@ def call(cmd, cmd_dir='.', fail=True):
@type fail: bool
'''
try:
- logging.info("Running command '%s'" % cmd)
+ m.message("Running command '%s'" % cmd)
shell = True
if PLATFORM == Platform.WINDOWS:
# windows do not understand ./
@@ -89,10 +91,15 @@ def call(cmd, cmd_dir='.', fail=True):
# Disable shell which uses cmd.exe
shell = False
stream = LOGFILE or sys.stdout
- ret = subprocess.check_call(cmd, cwd=cmd_dir,
- stderr=subprocess.STDOUT,
- stdout=StdOut(stream),
- env=os.environ.copy(), shell=shell)
+ if DRY_RUN:
+ # write to sdterr so it's filtered more easilly
+ m.error ("cd %s && %s && cd %s" % (cmd_dir, cmd, os.getcwd()))
+ ret = 0
+ else:
+ ret = subprocess.check_call(cmd, cwd=cmd_dir,
+ stderr=subprocess.STDOUT,
+ stdout=StdOut(stream),
+ env=os.environ.copy(), shell=shell)
except subprocess.CalledProcessError:
if fail:
raise FatalError(_("Error running command: %s") % cmd)