35 |
35 |
|
36 |
36 |
from image_creator import get_os_class
|
37 |
37 |
from image_creator import __version__ as version
|
|
38 |
from image_creator import util
|
38 |
39 |
from image_creator.disk import Disk
|
39 |
40 |
from image_creator.util import get_command, error, success, output, FatalError
|
40 |
|
from image_creator import util
|
|
41 |
from image_creator.kamaki_wrapper import Kamaki
|
41 |
42 |
import sys
|
42 |
43 |
import os
|
43 |
44 |
import optparse
|
... | ... | |
61 |
62 |
usage = "Usage: %prog [options] <input_media>"
|
62 |
63 |
parser = optparse.OptionParser(version=version, usage=usage)
|
63 |
64 |
|
64 |
|
parser.add_option("-f", "--force", dest="force", default=False,
|
65 |
|
action="store_true", help="overwrite output files if they exist")
|
66 |
|
|
67 |
|
parser.add_option("--no-sysprep", dest="sysprep", default=True,
|
68 |
|
help="don't perform system preperation", action="store_false")
|
69 |
|
|
70 |
|
parser.add_option("--no-shrink", dest="shrink", default=True,
|
71 |
|
help="don't shrink any partition", action="store_false")
|
|
65 |
account = os.environ["OKEANOS_USER"] if "OKEANOS_USER" in os.environ \
|
|
66 |
else None
|
|
67 |
token = os.environ["OKEANOS_TOKEN"] if "OKEANOS_TOKEN" in os.environ \
|
|
68 |
else None
|
72 |
69 |
|
73 |
70 |
parser.add_option("-o", "--outfile", type="string", dest="outfile",
|
74 |
71 |
default=None, action="callback", callback=check_writable_dir,
|
75 |
72 |
help="dump image to FILE", metavar="FILE")
|
76 |
73 |
|
77 |
|
parser.add_option("--enable-sysprep", dest="enabled_syspreps", default=[],
|
78 |
|
help="run SYSPREP operation on the input media",
|
79 |
|
action="append", metavar="SYSPREP")
|
80 |
|
|
81 |
|
parser.add_option("--disable-sysprep", dest="disabled_syspreps",
|
82 |
|
help="prevent SYSPREP operation from running on the input media",
|
83 |
|
default=[], action="append", metavar="SYSPREP")
|
84 |
|
|
85 |
|
parser.add_option("--print-sysprep", dest="print_sysprep", default=False,
|
86 |
|
help="print the enabled and disabled sysprep operations for this "
|
87 |
|
"input media", action="store_true")
|
|
74 |
parser.add_option("-f", "--force", dest="force", default=False,
|
|
75 |
action="store_true", help="overwrite output files if they exist")
|
88 |
76 |
|
89 |
77 |
parser.add_option("-s", "--silent", dest="silent", default=False,
|
90 |
78 |
help="silent mode, only output errors", action="store_true")
|
... | ... | |
97 |
85 |
default=False, help="register the image to ~okeanos as IMAGENAME",
|
98 |
86 |
metavar="IMAGENAME")
|
99 |
87 |
|
|
88 |
parser.add_option("-a", "--account", dest="account", type="string",
|
|
89 |
default=account,
|
|
90 |
help="Use this ACCOUNT when uploading/registring images [Default: %s]"\
|
|
91 |
% account)
|
|
92 |
|
|
93 |
parser.add_option("-t", "--token", dest="token", type="string",
|
|
94 |
default=token,
|
|
95 |
help="Use this token when uploading/registring images [Default: %s]"\
|
|
96 |
% token)
|
|
97 |
|
|
98 |
parser.add_option("--print-sysprep", dest="print_sysprep", default=False,
|
|
99 |
help="print the enabled and disabled system preparation operations "
|
|
100 |
"for this input media", action="store_true")
|
|
101 |
|
|
102 |
parser.add_option("--enable-sysprep", dest="enabled_syspreps", default=[],
|
|
103 |
help="run SYSPREP operation on the input media",
|
|
104 |
action="append", metavar="SYSPREP")
|
|
105 |
|
|
106 |
parser.add_option("--disable-sysprep", dest="disabled_syspreps",
|
|
107 |
help="prevent SYSPREP operation from running on the input media",
|
|
108 |
default=[], action="append", metavar="SYSPREP")
|
|
109 |
|
|
110 |
parser.add_option("--no-sysprep", dest="sysprep", default=True,
|
|
111 |
help="don't perform system preperation", action="store_false")
|
|
112 |
|
|
113 |
parser.add_option("--no-shrink", dest="shrink", default=True,
|
|
114 |
help="don't shrink any partition", action="store_false")
|
|
115 |
|
100 |
116 |
options, args = parser.parse_args(input_args)
|
101 |
117 |
|
102 |
118 |
if len(args) != 1:
|
... | ... | |
105 |
121 |
if not os.path.exists(options.source):
|
106 |
122 |
raise FatalError("Input media `%s' is not accessible" % options.source)
|
107 |
123 |
|
108 |
|
if options.register and options.upload == False:
|
|
124 |
if options.register and options.upload == False:
|
109 |
125 |
raise FatalError("You also need to set -u when -r option is set")
|
110 |
126 |
|
|
127 |
if options.upload and options.account is None:
|
|
128 |
raise FatalError("Image uploading cannot be performed. No ~okeanos "
|
|
129 |
"account name is specified. Use -a to set an account name.")
|
|
130 |
|
|
131 |
if options.upload and options.token is None:
|
|
132 |
raise FatalError("Image uploading cannot be performed. No ~okeanos "
|
|
133 |
"token is specified. User -t to set a token.")
|
|
134 |
|
111 |
135 |
return options
|
112 |
136 |
|
113 |
137 |
|
... | ... | |
176 |
200 |
f.close()
|
177 |
201 |
|
178 |
202 |
dev.dump(options.outfile)
|
|
203 |
|
|
204 |
if options.upload:
|
|
205 |
output("Uploading image to pithos...", False)
|
|
206 |
kamaki = Kamaki(options.account, options.token)
|
|
207 |
kamaki.upload(dev.device, size, options.upload)
|
|
208 |
output("done")
|
|
209 |
|
179 |
210 |
finally:
|
180 |
211 |
output('cleaning up...')
|
181 |
212 |
disk.cleanup()
|