46
46
class createLiveIso:
48
def __init__ (self, config, debootstrap):
48
def __init__(self, config, debootstrap):
49
49
''' This should create the live dir if it not exist '''
50
50
_filesHelper = fileUtils.fileUtils()
51
51
self.config = config
52
52
self.debootstrap = debootstrap
53
53
base_dir = self.config.get_key("project_dir")
54
_filesHelper.createDir (os.path.join (base_dir, LIVE_DIR))
55
_filesHelper.createDir (os.path.join (base_dir, LIVE_DIR, CASPER_DIR))
54
_filesHelper.createDir(os.path.join(base_dir, LIVE_DIR))
55
_filesHelper.createDir(os.path.join(base_dir, LIVE_DIR, CASPER_DIR))
57
if not os.path.isfile (MKSQUASHFSCOMMAND):
57
if not os.path.isfile(MKSQUASHFSCOMMAND):
58
58
print "Error, you must install squashfs-tools (apt-get install squashfs-tools)"
60
elif not os.access (MKSQUASHFSCOMMAND, os.X_OK):
60
elif not os.access(MKSQUASHFSCOMMAND, os.X_OK):
61
61
print "%s is not an executable file" % MKSQUASHFSCOMMAND
64
if not os.path.isfile (MKISOFSCMD):
64
if not os.path.isfile(MKISOFSCMD):
65
65
print "Error, you must install genisoimage (apt-get install genisoimage)"
67
elif not os.access (MKISOFSCMD, os.X_OK):
67
elif not os.access(MKISOFSCMD, os.X_OK):
68
68
print "%s is not an executable file" % MKISOFSCMD
75
def create_manifest (self):
75
def create_manifest(self):
76
76
''' Create mainfest and save it into a file '''
77
self.debootstrap._prepare_chroot ()
77
self.debootstrap._prepare_chroot()
79
casper_path = (os.path.join (self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR))
79
casper_path = (os.path.join(self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR))
81
if os.path.isfile (os.path.join (casper_path, MANIFEST_FILENAME)):
82
os.unlink (os.path.join (casper_path, MANIFEST_FILENAME))
83
if os.path.isfile (os.path.join (casper_path, MANIFEST_DESKTOP_FILENAME)):
84
os.unlink (os.path.join (casper_path, MANIFEST_DESKTOP_FILENAME))
81
if os.path.isfile(os.path.join(casper_path, MANIFEST_FILENAME)):
82
os.unlink(os.path.join(casper_path, MANIFEST_FILENAME))
83
if os.path.isfile(os.path.join(casper_path, MANIFEST_DESKTOP_FILENAME)):
84
os.unlink(os.path.join(casper_path, MANIFEST_DESKTOP_FILENAME))
86
86
LIVE_PACKAGES = self.config['live']
88
88
#TODO Add some checks here and there ...
89
manifest = open (os.path.join (casper_path, MANIFEST_FILENAME), "w")
90
manifest_desktop = open (os.path.join (casper_path, MANIFEST_DESKTOP_FILENAME), "w")
91
for package in os.popen("/usr/sbin/chroot %s dpkg-query -W --showformat='${Package} ${Version}\n'" % (os.path.join (self.config.get_key("project_dir"), SOURCE_DIR))).readlines():
92
manifest.write (package)
89
manifest = open(os.path.join(casper_path, MANIFEST_FILENAME), "w")
90
manifest_desktop = open(os.path.join(casper_path, MANIFEST_DESKTOP_FILENAME), "w")
91
for package in os.popen("/usr/sbin/chroot %s dpkg-query -W --showformat='${Package} ${Version}\n'" % (os.path.join(self.config.get_key("project_dir"), SOURCE_DIR))).readlines():
92
manifest.write(package)
93
93
if not package.split(' ')[0] in LIVE_PACKAGES:
94
manifest_desktop.write (package)
94
manifest_desktop.write(package)
97
manifest_desktop.close ()
98
self.debootstrap._close_chroot ()
97
manifest_desktop.close()
98
self.debootstrap._close_chroot()
100
def create_squashfs (self):
100
def create_squashfs(self):
101
101
''' Create squashfs file to use with casper
102
102
This method depends on squashfs-tools package
104
casper_path = os.path.join (self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR)
105
project_path = os.path.join (self.config.get_key("project_dir"), SOURCE_DIR)
104
casper_path = os.path.join(self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR)
105
project_path = os.path.join(self.config.get_key("project_dir"), SOURCE_DIR)
107
107
self.debootstrap.clean_chroot()
108
if os.path.isfile (os.path.join (casper_path, SQUASHFS_FILENAME)):
109
os.unlink (os.path.join (casper_path, SQUASHFS_FILENAME))
108
if os.path.isfile(os.path.join(casper_path, SQUASHFS_FILENAME)):
109
os.unlink(os.path.join(casper_path, SQUASHFS_FILENAME))
110
110
os.system("%s %s %s" % (
111
111
MKSQUASHFSCOMMAND,
112
112
os.path.join(project_path),
113
113
os.path.join(casper_path, SQUASHFS_FILENAME)
116
def copy_kernel_files (self):
116
def copy_kernel_files(self):
117
117
''' copy the files needed by isolinux to boot the live image '''
118
casper_path = (os.path.join (self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR))
119
project_path = os.path.join (self.config.get_key("project_dir"), SOURCE_DIR)
122
if os.path.isfile (os.path.join (casper_path, INITRD_FILENAME)):
123
os.unlink (os.path.join (casper_path, INITRD_FILENAME))
118
casper_path = (os.path.join(self.config.get_key("project_dir"), LIVE_DIR, CASPER_DIR))
119
project_path = os.path.join(self.config.get_key("project_dir"), SOURCE_DIR)
122
if os.path.isfile(os.path.join(casper_path, INITRD_FILENAME)):
123
os.unlink(os.path.join(casper_path, INITRD_FILENAME))
125
shutil.copyfile (os.path.join (project_path, 'initrd.img'), os.path.join (casper_path, INITRD_FILENAME ))
125
shutil.copyfile(os.path.join(project_path, 'initrd.img'), os.path.join(casper_path, INITRD_FILENAME))
126
126
except IOError, e:
128
128
print "You won't be able to boot without initrd.img"
131
if os.path.isfile (os.path.join (casper_path, VMLINUZ_FILENAME)):
132
os.unlink (os.path.join (casper_path, VMLINUZ_FILENAME))
131
if os.path.isfile(os.path.join(casper_path, VMLINUZ_FILENAME)):
132
os.unlink(os.path.join(casper_path, VMLINUZ_FILENAME))
134
shutil.copyfile (os.path.join (project_path, 'vmlinuz'), os.path.join (casper_path, VMLINUZ_FILENAME ))
134
shutil.copyfile(os.path.join(project_path, 'vmlinuz'), os.path.join(casper_path, VMLINUZ_FILENAME ))
135
135
except IOError, e:
137
137
print "You won't be able to boot without vmlinuz"
142
142
''' This method create the bootable iso '''
143
143
print "------------------------------------------------- copying isolinux ---"
144
144
# Rsync better -- CUT HERE --
211
class createUSBImage (createLiveIso):
211
class createUSBImage(createLiveIso):
213
def __init__ (self, config, debootstrap, sizeInMb):
213
def __init__(self, config, debootstrap, sizeInMb):
214
214
''' This should create the live dir if it not exist and the ext3 image'''
215
215
_filesHelper = fileUtils.fileUtils()
216
216
self.config = config
217
217
self.debootstrap = debootstrap
218
self.usbImgFile = os.path.join (
218
self.usbImgFile = os.path.join(
219
219
self.config.get_key("project_dir"),
220
220
self.config.get_key("project_name") + ".ext3"
222
222
base_dir = self.config.get_key("project_dir")
223
_filesHelper.createDir (os.path.join (base_dir, LIVE_DIR))
224
os.system ("/bin/dd if=/dev/zero of=%s count=1 bs=%dM" % (self.usbImgFile, sizeInMb))
225
os.system ("/sbin/mkfs.ext3" % self.usbImgFile)
223
_filesHelper.createDir(os.path.join(base_dir, LIVE_DIR))
224
os.system("/bin/dd if=/dev/zero of=%s count=1 bs=%dM" % (self.usbImgFile, sizeInMb))
225
os.system("/sbin/mkfs.ext3" % self.usbImgFile)
226
226
os.system("/bin/mount -o loop %s %s") % (
228
os.path.join (base_dir, LIVE_DIR)
228
os.path.join(base_dir, LIVE_DIR)
232
232
''' This method create the bootable iso '''
233
233
print "------------------------------------------------- copying syslinux ---"
234
234
shutil.rmtree(os.path.join(self.config.get_key("project_dir"), LIVE_DIR, 'syslinux'), True)
235
shutil.copytree (SYSLINUX, os.path.join (self.config.get_key("project_dir"), LIVE_DIR, 'syslinux'))
236
os.system("/bin/umount %s") % os.path.join (self.config.get_key("project_dir"), LIVE_DIR)
235
shutil.copytree(SYSLINUX, os.path.join(self.config.get_key("project_dir"), LIVE_DIR, 'syslinux'))
236
os.system("/bin/umount %s") % os.path.join(self.config.get_key("project_dir"), LIVE_DIR)
240
240
class createDebianInstallerIso:
242
def __init__ (self, config):
242
def __init__(self, config):
243
243
''' This should create the debian-installer dir if it not exist.
244
244
This class depends on simple-cdd and devscripts '''
245
245
_filesHelper = fileUtils.fileUtils()
246
246
self.config = config
247
247
base_dir = self.config.get_key("project_dir")
248
248
print "Base dir: ", base_dir
249
_filesHelper.createDir (os.path.join (base_dir, DI_DIR))
249
_filesHelper.createDir(os.path.join(base_dir, DI_DIR))
250
250
self.cwd = os.getcwd()
251
os.chdir (os.path.join (base_dir, DI_DIR))
251
os.chdir(os.path.join(base_dir, DI_DIR))
252
252
os.system('dget simple-cdd-profiles')
255
def addToProfile (self, package):
255
def addToProfile(self, package):
256
256
'''Add a package to the profile fle.'''
257
_filesHelper.createDir (os.path.join (self.config.get_key("project_dir"), DI_DIR, 'profiles'))
257
_filesHelper.createDir(os.path.join(self.config.get_key("project_dir"), DI_DIR, 'profiles'))
260
260
self.config.get_key("project_dir"),
263
263
'%s.packages' % self.config.get_key("project_name")
266
profile.write (package)
266
profile.write(package)
270
270
''' This method create the bootable iso '''
271
os.chdir (self.config.get_key("project_dir"))
271
os.chdir(self.config.get_key("project_dir"))
272
272
cmd = "/usr/bin/build-simple-cdd --profiles %s --local-packages %s/simple-cdd-profiles_*.udeb" % (
273
273
self.config.get_key("project_dir"), DI_DIR