-
Notifications
You must be signed in to change notification settings - Fork 3
patch sbdmock shell command
GrahamCobb edited this page Sep 13, 2010
·
1 revision
diff --git a/scripts/sbdmock b/scripts/sbdmock
index 5ce3c72..5b98980 100755
--- a/scripts/sbdmock
+++ b/scripts/sbdmock
@@ -301,6 +301,13 @@ class SBBuilder:
return (retval, output)
+ def shell(self, args):
+ """execute a shell command in scratchbox target"""
+
+ self.state("shell")
+
+ self.do_chroot_ng(' '.join(args))
+
def build(self, dsc):
"""build an source package into binary debs, capture log"""
@@ -696,7 +703,7 @@ class SBBuilder:
# We will only read from pipe
pipe.tochild.close()
- if self.state() == "build":
+ if self.state() == "build" or self.state() == "shell":
logfile = self._build_log
else:
logfile = self._root_log
@@ -895,6 +902,7 @@ def command_parse():
usage = """
usage: sbdmock [options] /path/to/dsc
+ usage: sbdmock [options] -c shell command with arguments
optional commands:
clean - clean out the specified chroot
init - initialize the chroot, do not build anything"""
@@ -930,6 +938,8 @@ def command_parse():
help="Modifiers for DEB_BUILD_OPTIONS (e.g. '+debug,-parallel')")
parser.add_option("--define", action="append", type="string", default=None,
help="Define variables which might be used in other variables. Format: name=value")
+ parser.add_option("-c", action="store_true", dest="command", default=False,
+ help="Interpret arguments as a shell command to execute in the scratchbox")
return parser.parse_args()
@@ -1083,7 +1093,35 @@ def main():
my = None
# do whatever we're here to do
- if args[0] == 'clean':
+ if options.command:
+ # execute a shell command
+ if options.genext and not config_opts['uniqueext']:
+ def gen_uniqid(dsc, target):
+ import sha
+ hash_string = "%d%s%s" % (os.getpid(), target, dsc)
+ sha_hash = sha.new()
+ sha_hash.update(hash_string)
+ return sha_hash.hexdigest()
+ config_opts['uniqueext'] = gen_uniqid(args[0], options.target)
+ config_opts['uniqueext-auto'] = True
+
+ start_time = time.time()
+ try:
+ my = SBBuilder(config_opts)
+ my.prep()
+ my.shell(args)
+ except Error, err:
+ error("Error occured: %s" % err.msg)
+ if my:
+ my.close()
+ sys.exit(err.resultcode)
+
+ my.close()
+ stop_time = time.time()
+ print "Elapsed time %s" % time.strftime("%T", time.gmtime(stop_time-start_time))
+ print "Logs in: %s" % my.resultdir
+
+ elif args[0] == 'clean':
# unset a --no-clean
config_opts['clean'] = True
try: