+dd = get_command('dd')
+
+
+def check_writable_dir(option, opt_str, value, parser):
+ dirname = os.path.dirname(value)
+ name = os.path.basename(value)
+ if dirname and not os.path.isdir(dirname):
+ parser.error("`%s' is not an existing directory" % dirname)
+
+ if not name:
+ parser.error("`%s' is not a valid file name" % dirname)
+
+ setattr(parser.values, option.dest, value)
+
+
+def parse_options(input_args):
+ usage = "Usage: %prog [options] <input_media>"
+ parser = optparse.OptionParser(version=version, usage=usage)
+
+ parser.add_option("-f", "--force", dest="force", default=False,
+ action="store_true", help="overwrite output files if they exist")
+
+ parser.add_option("--no-cleanup", dest="cleanup", default=True,
+ help="don't cleanup sensitive data", action="store_false")
+
+ parser.add_option("--no-sysprep", dest="sysprep", default=True,
+ help="don't perform system preperation", action="store_false")
+
+ parser.add_option("--no-shrink", dest="shrink", default=True,
+ help="don't shrink any partition", action="store_false")
+
+ parser.add_option("-o", "--outfile", type="string", dest="outfile",
+ default=None, action="callback", callback=check_writable_dir,
+ help="dump image to FILE", metavar="FILE")
+
+ parser.add_option("-s", "--silent", dest="silent", default=False,
+ help="silent mode, only output error", action="store_true")
+
+ parser.add_option("-u", "--upload", dest="upload", default=False,
+ help="upload the image to pithos", action="store_true")
+
+ parser.add_option("-r", "--register", dest="register", default=False,
+ help="register the image to ~okeanos", action="store_true")
+
+ options, args = parser.parse_args(input_args)
+
+ if len(args) != 1:
+ parser.error('Wrong number of arguments')
+ options.source = args[0]
+ if not os.path.exists(options.source):
+ parser.error('input media is not accessible')
+
+ if options.register:
+ options.upload = True
+
+ if options.outfile is None and not options.upload:
+ parser.error('either outfile (-o) or upload (-u) must be set.')