def preData(self): pre_buffer = self.pre_textview.get_buffer() data = pre_buffer.get_text(pre_buffer.get_start_iter(), pre_buffer.get_end_iter(), True) data = string.strip(data) if data == "": return preScripts = filter(lambda s: s.type == KS_SCRIPT_PRE, self.ks.scripts) if len(preScripts) == 0: script = Script("", type=KS_SCRIPT_PRE) else: script = preScripts[0] if self.pre_interpreter_checkbutton.get_active(): script.interp = self.pre_interpreter_entry.get_text() else: script.interp = "" script.script = data if len(preScripts) == 0: self.ks.scripts.append(script)
def runTest(self): self.get_parser() obj = Script("ls /\n", type=KS_SCRIPT_POST) self.assertEqual(str(obj), """ %post --nochroot ls / """) obj = Script("ls /", type=KS_SCRIPT_POST) self.assertEqual(str(obj), """ %post --nochroot ls / """)
def embed_script(self, tarball): if tarball is None: return tarball_content = None if os.path.exists(tarball): tarball_content = FileHelper.get_file_content(tarball, 'rb', decode_flag=False) tarball_name = os.path.splitext( os.path.splitext(os.path.basename(tarball))[0])[0] script_str = '' try: script_path = settings.KS_TEMPLATE_POSTSCRIPT except AttributeError: log_message( 'KS_TEMPLATE_POSTSCRIPT is not defined in settings.py.') return script_str = FileHelper.get_file_content( os.path.join(settings.KS_DIR, script_path), 'rb') if not script_str: log_message( "Cannot open the script template: {0}.".format(script_path)) return if tarball_content is not None: script_str = script_str.replace('{tar_ball}', base64.b64encode(tarball_content)) script_str = script_str.replace('{RESULT_NAME}', tarball_name) script_str = script_str.replace('{TEMPORARY_PREUPG_DIR}', '/root/preupgrade') script = Script(script_str, type=KS_SCRIPT_POST, inChroot=True) self.ks.handler.scripts.append(script)
def postData(self): post_buffer = self.post_textview.get_buffer() data = post_buffer.get_text(post_buffer.get_start_iter(), post_buffer.get_end_iter(), True) data = string.strip(data) if data == "": return postScripts = filter(lambda s: s.type == KS_SCRIPT_POST, self.ks.scripts) if len(postScripts) == 0: script = Script("", type=KS_SCRIPT_POST) else: script = postScripts[0] if self.chroot_checkbutton.get_active(): script.inChroot = False else: script.inChroot = True if self.interpreter_checkbutton.get_active(): script.interp = self.interpreter_entry.get_text() else: script.interp = "" script.script = data if len(postScripts) == 0: self.ks.scripts.append(script)
def runTest(self): self.handler.platform = "x86_64" self.assertIn("#platform=x86_64", str(self.handler)) self.handler.platform = "" self.assertNotIn("#platform", str(self.handler)) self.handler.scripts.append(Script("echo Hello", type=KS_SCRIPT_POST)) self.assertIn("echo Hello", str(self.handler))
def update_partitioning(self): if self.part_layout is None: return # Index 1 means size script_str = [ 'echo "# This is partition layout generated by preupg --kickstart command" > %s' % self.temp_file ] script_str.extend([ 'echo "%s" >> %s' % (line, self.temp_file) for line in self.part_layout ]) script = Script('\n'.join(script_str), type=KS_SCRIPT_PRE, inChroot=True) self.ks.handler.scripts.append(script)
def embed_script(self, tarball): tarball_content = get_file_content(tarball, 'rb', decode_flag=False) tarball_name = os.path.splitext( os.path.splitext(os.path.basename(tarball))[0])[0] script_str = '' try: script_path = settings.KS_TEMPLATE_POSTSCRIPT except AttributeError: log_message('KS_TEMPLATE_POSTSCRIPT is not defined in settings.py') return script_str = get_file_content( os.path.join(settings.KS_DIR, script_path), 'rb') if not script_str: log_message("Can't open script template: {0}".format(script_path)) return script_str = script_str.replace('{tar_ball}', base64.b64encode(tarball_content)) script_str = script_str.replace('{RESULT_NAME}', tarball_name) script = Script(script_str, type=KS_SCRIPT_POST, inChroot=True) self.ks.handler.scripts.append(script)
def runTest(self): # The parser object will never be set up by this test, which means the # Script object will get the version number of whatever ran last. That # could be totally wrong. Thus, cause the parser to be created here # so the version will be right. self.get_parser() body = "import sys\nsys.exit(1)\n" obj = Script(body, type=KS_SCRIPT_PRE, interp="/usr/bin/python", logfile="/tmp/log", errorOnFail=True) self.assertEqual(obj.type, KS_SCRIPT_PRE) self.assertEqual(obj.interp, "/usr/bin/python") self.assertEqual(obj.logfile, "/tmp/log") self.assertTrue(obj.errorOnFail) self.assertEqual( str(obj), """ %pre --interpreter=/usr/bin/python --logfile=/tmp/log --erroronfail import sys sys.exit(1) %end """) obj = Script("ls /", type=KS_SCRIPT_POST, inChroot=False) self.assertEqual(obj.type, KS_SCRIPT_POST) self.assertFalse(obj.inChroot) self.assertEqual(str(obj), """ %post --nochroot ls / %end """) obj = Script("ls /", type=KS_SCRIPT_PREINSTALL) self.assertEqual(obj.type, KS_SCRIPT_PREINSTALL) self.assertEqual(str(obj), """ %pre-install ls / %end """) obj = Script("ls /", type=KS_SCRIPT_TRACEBACK) self.assertEqual(obj.type, KS_SCRIPT_TRACEBACK) self.assertEqual(str(obj), """ %traceback ls / %end """) obj = Script("ls /", type=KS_SCRIPT_ONERROR) self.assertEqual(obj.type, KS_SCRIPT_ONERROR) self.assertEqual(str(obj), """ %onerror ls / %end """)