def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list( self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.suite = get_suite(self.conn, self.profile) self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite)
def __init__(self, conn, suite, name='EnvironmentEditor'): self.menu = make_menu(['update', 'create'], self.env_command) _EnvironmentEditor.__init__(self, conn, name=name) self.suite = suite self.traitparent = TraitParent(self.conn, self.suite) self.current_trait = None self.reset_rows() w, h = map( int, config.get_list('env_editor_size', section='management_gui')) self.set_size_request(w, h)
def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite
def set_profile(self, profile): self.profile = profile os.environ['PAELLA_PROFILE'] = profile self.profiletrait.set_profile(profile) self.traits = self.profiletrait.trait_rows() self.env = ProfileEnvironment(self.conn, self.profile) self.profiledata = self.get_profile_data() self.suite = get_suite(self.conn, profile) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) self.installer.log = self.log self.installer.profiledata = self.profiledata self.traitparent = TraitParent(self.conn, self.suite) self.log.info('profile set to %s' % profile)
def install_packages_uml(conn, suite, profile, target): traits = get_traits(conn, profile) tp = TraitParent(conn, suite) pp = TraitPackage(conn, suite) packages = ' '.join([p.package for p in pp.all_packages(traits, tp)]) os.system('chroot %s apt-get update' % target) os.system('chroot %s apt-get -y install %s' % (target, packages))
def make_traitlist(self): tp = TraitParent(self.conn, self.suite) listed = [x.trait for x in self.profiletrait.trait_rows()] all = list(self.traitparent.get_traitset(listed)) setfun = tp.set_trait parfun = tp.parents log = self.log return make_deplist(listed, all, setfun, parfun, log)
class EnvironmentEditor(_EnvironmentEditor): def __init__(self, conn, suite, name='EnvironmentEditor'): self.menu = make_menu(['update', 'create'], self.env_command) _EnvironmentEditor.__init__(self, conn, name=name) self.suite = suite self.traitparent = TraitParent(self.conn, self.suite) self.current_trait = None self.reset_rows() w, h = map(int, config.get_list('env_editor_size', section='management_gui')) self.set_size_request(w, h) def reset_rows(self): rows = self.main.select(fields=['trait'], table=ujoin(self.suite, 'traits')) self.set_rows(rows) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0].trait self.select_trait(trait) def select_trait(self, trait): self.current_trait = trait environ = TraitEnvironment(self.conn, self.suite, trait) self.environ = self.traitparent.get_environment([self.current_trait]) self.sections = dict([(k, v.keys()) for k,v in self.environ]) self.remove_page('Environment') self.record = RecordBox(environ, name=self.current_trait) self.append_page(self.record, 'Environment') self.pages['Environment'].connect('button_press_event', self.box_pressed) #self.menu.connect('populate', self.populate_menu, self.menu) self.record.connect_entries('populate-popup', self.populate_menu, self.menu) def make_new_variable(self, *args): d = self.dialogs['create'] environ = TraitEnvironment(self.conn, self.suite, self.current_trait) environ.update(dict([(d['name'], d['value'])])) def remove_item(self, *args): d = self.dialogs['remove'] name = d.get_selected_data()[0].name environ = TraitEnvironment(self.conn, self.suite, self.current_trait) del environ[name] dialogs.Message('%s deleted' %name) self.destroy_dialog(d) def update_environment(self): environ = TraitEnvironment(self.conn, self.suite, self.current_trait) environ.update(self.record) def env_command(self, menuitem, command): if command == 'update': dialogs.Message('updating %s' % self.current_trait) self.update_environment() elif command == 'create': self.ask_new_entry() else: dialogs.Message('ack')
class InstallerTools(object): def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.suite = get_suite(self.conn, self.profile) self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) def env(self): env = self.tp.Environment() env.update(self.pe.ProfileData()) return env def set_trait(self, trait): self.tp.set_trait(trait)
def __init__(self, conn, suite, name='EnvironmentEditor'): self.menu = make_menu(['update', 'create'], self.env_command) _EnvironmentEditor.__init__(self, conn, name=name) self.suite = suite self.traitparent = TraitParent(self.conn, self.suite) self.current_trait = None self.reset_rows() w, h = map(int, config.get_list('env_editor_size', section='management_gui')) self.set_size_request(w, h)
def make_traitlist_orig(self): traitparent = TraitParent(self.conn, self.suite) profile_traits = [x.trait for x in self.profiletrait.trait_rows()] all_traits = list(self.traitparent.get_traitset(profile_traits)) traitlist = [] while len(profile_traits): profile_traits_prepended = False trait = profile_traits[0] traitparent.set_trait(trait) parents = [r.parent for r in traitparent.parents()] for p in parents: if not profile_traits_prepended and p not in traitlist: profile_traits = [p] + profile_traits profile_traits_prepended = True self.log.info('profile_traits prepended with %s' % p) if not profile_traits_prepended: traitlist.append(trait) del profile_traits[0] self.log.info('%s %s' % (str(traitlist), profile_traits)) return traitlist
def make_traitlist_orig(self): traitparent = TraitParent(self.conn, self.suite) profile_traits = [x.trait for x in self.profiletrait.trait_rows()] all_traits = list(self.traitparent.get_traitset(profile_traits)) traitlist = [] while len(profile_traits): profile_traits_prepended = False trait = profile_traits[0] traitparent.set_trait(trait) parents = [r.parent for r in traitparent.parents()] for p in parents: if not profile_traits_prepended and p not in traitlist: profile_traits = [p] + profile_traits profile_traits_prepended = True self.log.info("profile_traits prepended with %s" % p) if not profile_traits_prepended: traitlist.append(trait) del profile_traits[0] self.log.info("%s %s" % (str(traitlist), profile_traits)) return traitlist
def set_profile(self, profile): self.profile = profile self._profile.set_profile(profile) os.environ["PAELLA_PROFILE"] = profile self.profiletrait.set_profile(profile) self.traits = self.profiletrait.trait_rows() self.env = ProfileEnvironment(self.conn, self.profile) self.familydata = self._profile.get_family_data() self.profiledata = self._profile.get_profile_data() self.suite = get_suite(self.conn, profile) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) self.installer.log = self.log self.installer.familydata = self.familydata self.installer.profiledata = self.profiledata self.traitparent = TraitParent(self.conn, self.suite) self.log.info("profile set to %s" % profile)
def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list(self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT'])
class TemplateEnvironment(ScrolledWindow): def __init__(self, conn): ScrolledWindow.__init__(self) self.conn = conn self.editor = TemplateEditor() self.menu = SimpleMenu() self.editor.connect('populate-popup', self.populate_menu, self.menu) self.add_with_viewport(self.editor) self.show() def set_suite(self, suite): self.suite = suite self.__set_suitecursors__() def __set_suitecursors__(self): self.traitparent = TraitParent(self.conn, self.suite) self.traittemplate = TraitTemplate(self.conn, self.suite) self.traitpackage = TraitPackage(self.conn, self.suite) def set_trait(self, trait): self.trait = trait self.traitparent.set_trait(trait) self.traittemplate.set_trait(trait) self.traitpackage.set_trait(trait) self.__set_environment__() def __set_environment__(self): self.environ = dict(self.traitparent.get_environment([self.trait])) self.sections = dict([(k, v.keys()) for k,v in self.environ.items()]) def populate_menu(self, widget, mainmenu, tmenu): self.__set_environment__() populate_menu(mainmenu, '_define_', ['_create_'], self.make_new_tag) for section, vars in self.sections.items(): populate_menu(mainmenu, section, vars, self.make_tag) def make_tag(self, menuitem, name, parent): parentname = parent.get_name() tagname = ujoin(parentname, name) self.editor.make_tag(tagname) def make_new_tag(self, menuitem, name, parent): parentname = parent.get_name() if (parentname, name) == ('_define_', '_create_'): self.editor.create_new_tag(self.create_entry) def create_entry(self, *args): var = dict(self.editor.dialogs['create'].items()) debug('var is %s' % var) self.environ[self.trait][var['name']] = var['value'] tagname = ujoin(self.trait, var['name']) self.editor.make_tag(tagname) self.editor.destroy_dialog(self.editor.dialogs['create']) def preview(self, *args): subs = self.traitparent.get_superdict(self.environ.keys()) self.editor.buffer.set_subs(subs) self.editor.preview(*args) def set_text(self, text): self.editor.buffer.set_text(text) def get_text(self): return self.editor.get_text()
class ProfileInstaller(Installer): def __init__(self, conn, cfg): os.environ["DEBIAN_FRONTEND"] = "noninteractive" Installer.__init__(self, conn, cfg) self.profiletrait = ProfileTrait(self.conn) self.profile = None self.installer = None self.cfg = cfg self._profile = Profile(self.conn) self.log.info("profile installer initialized") def set_profile(self, profile): self.profile = profile self._profile.set_profile(profile) os.environ["PAELLA_PROFILE"] = profile self.profiletrait.set_profile(profile) self.traits = self.profiletrait.trait_rows() self.env = ProfileEnvironment(self.conn, self.profile) self.familydata = self._profile.get_family_data() self.profiledata = self._profile.get_profile_data() self.suite = get_suite(self.conn, profile) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) self.installer.log = self.log self.installer.familydata = self.familydata self.installer.profiledata = self.profiledata self.traitparent = TraitParent(self.conn, self.suite) self.log.info("profile set to %s" % profile) def get_profile_data(self): return self.env.ProfileData() def set_logpath(self, logpath): Installer.set_logpath(self, logpath) if hasattr(self, "installer"): self.installer.set_logpath(logpath) def make_traitlist_orig(self): traitparent = TraitParent(self.conn, self.suite) profile_traits = [x.trait for x in self.profiletrait.trait_rows()] all_traits = list(self.traitparent.get_traitset(profile_traits)) traitlist = [] while len(profile_traits): profile_traits_prepended = False trait = profile_traits[0] traitparent.set_trait(trait) parents = [r.parent for r in traitparent.parents()] for p in parents: if not profile_traits_prepended and p not in traitlist: profile_traits = [p] + profile_traits profile_traits_prepended = True self.log.info("profile_traits prepended with %s" % p) if not profile_traits_prepended: traitlist.append(trait) del profile_traits[0] self.log.info("%s %s" % (str(traitlist), profile_traits)) return traitlist def make_traitlist(self): tp = TraitParent(self.conn, self.suite) listed = [x.trait for x in self.profiletrait.trait_rows()] all = list(self.traitparent.get_traitset(listed)) setfun = tp.set_trait parfun = tp.parents log = self.log return make_deplist(listed, all, setfun, parfun, log) def process(self): traits = self.make_traitlist() self.processed = [] for trait in traits: self.process_trait(trait) self.log.info("currently processed %s" % ",".join(self.processed)) self.log.info("all traits processed for profile %s" % self.profile) self.log.info("------------------------------------") def process_trait(self, trait): self.traitparent.set_trait(trait) self.installer.set_trait(trait) parents = [r.parent for r in self.traitparent.parents()] for p in parents: if p not in self.processed: raise UnbornError self.log.info("processing trait %s" % trait) self.installer.process() self.processed.append(trait) self.log.info("processed: %s" % ", ".join(self.processed)) def set_template_path(self, path): self.installer.set_template_path(path) def set_target(self, target, update=False): Installer.set_target(self, target) self.installer.set_target(target) if update: os.system(self.command("apt-get update")) def install_kernel(self, package): os.system(self.command("touch /boot/vmlinuz-fake")) os.system(self.command("ln -s boot/vmlinuz-fake vmlinuz")) os.system(self.command("apt-get -y install %s" % package)) print "kernel %s installed" % package
def __set_suitecursors__(self): self.traitparent = TraitParent(self.conn, self.suite) self.traittemplate = TraitTemplate(self.conn, self.suite) self.traitpackage = TraitPackage(self.conn, self.suite)
class TemplateEnvironment(ScrolledWindow): def __init__(self, conn): ScrolledWindow.__init__(self) self.conn = conn self.editor = TemplateEditor() self.menu = SimpleMenu() self.editor.connect('populate-popup', self.populate_menu, self.menu) self.add_with_viewport(self.editor) self.show() def set_suite(self, suite): self.suite = suite self.__set_suitecursors__() def __set_suitecursors__(self): self.traitparent = TraitParent(self.conn, self.suite) self.traittemplate = TraitTemplate(self.conn, self.suite) self.traitpackage = TraitPackage(self.conn, self.suite) def set_trait(self, trait): self.trait = trait self.traitparent.set_trait(trait) self.traittemplate.set_trait(trait) self.traitpackage.set_trait(trait) self.__set_environment__() def __set_environment__(self): self.environ = dict(self.traitparent.get_environment([self.trait])) self.sections = dict([(k, v.keys()) for k, v in self.environ.items()]) def populate_menu(self, widget, mainmenu, tmenu): self.__set_environment__() populate_menu(mainmenu, '_define_', ['_create_'], self.make_new_tag) for section, vars in self.sections.items(): populate_menu(mainmenu, section, vars, self.make_tag) def make_tag(self, menuitem, name, parent): parentname = parent.get_name() tagname = ujoin(parentname, name) self.editor.make_tag(tagname) def make_new_tag(self, menuitem, name, parent): parentname = parent.get_name() if (parentname, name) == ('_define_', '_create_'): self.editor.create_new_tag(self.create_entry) def create_entry(self, *args): var = dict(self.editor.dialogs['create'].items()) debug('var is %s' % var) self.environ[self.trait][var['name']] = var['value'] tagname = ujoin(self.trait, var['name']) self.editor.make_tag(tagname) self.editor.destroy_dialog(self.editor.dialogs['create']) def preview(self, *args): subs = self.traitparent.get_superdict(self.environ.keys()) self.editor.buffer.set_subs(subs) self.editor.preview(*args) def set_text(self, text): self.editor.buffer.set_text(text) def get_text(self): return self.editor.get_text()
class InstallerTools(object): def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list(self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT']) def env(self): env = RefDict(self.tp.Environment()) env.update(self.pr.get_family_data()) env.update(self.pr.get_profile_data()) return env def set_trait(self, trait): self.trait = trait self.tp.set_trait(trait) self.tr.set_trait(trait) self.parents = self.tr.parents() self._envv = self.env() self.installer.set_trait(trait) self.packages = self.installer.traitpackage.packages() self.templates = self.installer.traittemplate.templates() def get(self, key): if self._envv is None: raise Error, 'need to set trait first' return self._envv.dereference(key) def install_modules(self, name): modules = str2list(self.get(name)) print 'installing modules', modules, 'to %s/etc/modules' % self.target setup_modules(self.target, modules) def remove_packages(self, packages=None): if packages is None: packages = self.packages if len(packages): if hasattr(packages[0], 'package'): packages = [p.package for p in packages] package_list = ' '.join(packages) command = 'apt-get -y remove %s' % package_list self.installer.run('remove', command, proc=True)
class TraitTemplateBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite def modify_trait(self, menuitem, action): if action == 'hello': dialogs.Message('hello') elif action in ['import', 'update']: filesel = select_a_file(action, self.tarball_path + '/', self.select_trait_tarball) elif action in ['updatedir', 'exportdir', 'importdir']: filesel = select_a_file(action, self.tarball_path + '/', self.select_traitdir) elif action == 'export': try: trait = self.listbox.get_selected_data()[0].trait #self.pages[trait].extract_packages() self.select_export_path(trait) except IndexError: dialogs.Message('no trait selected') elif action == 'extract': try: trait = self.listbox.get_selected_data()[0].trait self.pages[trait].extract_packages() except IndexError: dialogs.Message('no trait selected') def reset_rows(self): if self.trait_selection == '_all_traits_': rows = self.traits.select(fields=['trait']) self.set_rows(rows) else: clause = Eq('profile', self.trait_selection) rows = self.cursor.select(fields=['trait'], table='profile_trait', clause=clause) ptraits = [x.trait for x in rows] traits = self._parents.get_traitset(ptraits) self.set_rows(list(traits), [self.trait_selection]) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0][0] self.select_trait(trait) def select_trait(self, trait): if trait not in self.pages: newpage = TemplateBrowser(self.conn, self.traits.suite, trait) self.append_page(newpage, trait) self.set_current_page(trait) def set_suite(self, suite): self.suite = suite self.traits.set_suite(suite) for page in self.pages: self.remove_page(page) self.reset_rows() def select_traitdir(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if not isdir(path): path = dirname(path) if not isdir(path): raise Error, '%s not found' % path if action in ['updatedir', 'importdir']: if action == 'updatedir': tcmd = 'update' elif action == 'importdir': tcmd = 'import' traits = [t.trait for t in self.traits.select()] if tcmd == 'update': ls = [ f for f in os.listdir(path) if f[-4:] == '.tar' and f[:-4] in traits ] for f in ls: self.importupdate(join(path, f), tcmd) elif tcmd == 'import': ls = [f for f in os.listdir(path) if f[-4:] == '.tar'] traits = [t[:-4] for t in ls] while len(traits): trait = traits[0] try: self.importupdate(join(path, trait + '.tar'), tcmd) except UnbornError: traits.append(trait) del traits[0] print 'processed', trait elif action == 'exportdir': self.select_export_path('_all_traits_') def select_trait_tarball(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() self.importupdate(path, action) def importupdate(self, path, action): tarball = TraitTarFile(path) trait = tarball.get_trait() traitdb = Trait(self.conn, self.suite) if action == 'import': traitdb.insert_trait(path, suite=self.suite) for info in tarball: if info.name[:10] == 'templates/': #tarball.extract(info, template_path) pass self.reset_rows() def select_export_path(self, trait): filesel = select_a_file(trait, self.tarball_path + '/', self.export_path_selected) def export_path_selected(self, button, filesel): trait = filesel.get_data('action') path = dirname(filesel.get_filename()) filesel.destroy() if trait == '_all_traits_': traits = [t.trait for t in self.traits.select()] for t in traits: self.export_trait(t, path) else: self.export_trait(trait, path) def export_trait(self, trait, path=None): if path is None: path = self.tarball_path tt = TraitTemplate(self.conn, self.suite) tt.set_trait(trait) backup_trait(self.conn, self.suite, trait, path) dialogs.Message('%s exported to %s' % (trait, path))
class EnvironmentEditor(_EnvironmentEditor): def __init__(self, conn, suite, name='EnvironmentEditor'): self.menu = make_menu(['update', 'create'], self.env_command) _EnvironmentEditor.__init__(self, conn, name=name) self.suite = suite self.traitparent = TraitParent(self.conn, self.suite) self.current_trait = None self.reset_rows() w, h = map( int, config.get_list('env_editor_size', section='management_gui')) self.set_size_request(w, h) def reset_rows(self): rows = self.main.select(fields=['trait'], table=ujoin(self.suite, 'traits')) self.set_rows(rows) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0].trait self.select_trait(trait) def select_trait(self, trait): self.current_trait = trait environ = TraitEnvironment(self.conn, self.suite, trait) self.environ = self.traitparent.get_environment([self.current_trait]) self.sections = dict([(k, v.keys()) for k, v in self.environ]) self.remove_page('Environment') self.record = RecordBox(environ, name=self.current_trait) self.append_page(self.record, 'Environment') self.pages['Environment'].connect('button_press_event', self.box_pressed) #self.menu.connect('populate', self.populate_menu, self.menu) self.record.connect_entries('populate-popup', self.populate_menu, self.menu) def make_new_variable(self, *args): d = self.dialogs['create'] environ = TraitEnvironment(self.conn, self.suite, self.current_trait) environ.update(dict([(d['name'], d['value'])])) def remove_item(self, *args): d = self.dialogs['remove'] name = d.get_selected_data()[0].name environ = TraitEnvironment(self.conn, self.suite, self.current_trait) del environ[name] dialogs.Message('%s deleted' % name) self.destroy_dialog(d) def update_environment(self): environ = TraitEnvironment(self.conn, self.suite, self.current_trait) environ.update(self.record) def env_command(self, menuitem, command): if command == 'update': dialogs.Message('updating %s' % self.current_trait) self.update_environment() elif command == 'create': self.ask_new_entry() else: dialogs.Message('ack')
class ProfileInstaller(Installer): def __init__(self, conn, cfg): os.environ['DEBIAN_FRONTEND'] = 'noninteractive' Installer.__init__(self, conn, cfg) self.profiletrait = ProfileTrait(self.conn) self.profile = None self.installer = None self.cfg = cfg self._profile = Profile(self.conn) self.log.info('profile installer initialized') def set_profile(self, profile): self.profile = profile self._profile.set_profile(profile) os.environ['PAELLA_PROFILE'] = profile self.profiletrait.set_profile(profile) self.traits = self.profiletrait.trait_rows() self.env = ProfileEnvironment(self.conn, self.profile) self.familydata = self._profile.get_family_data() self.profiledata = self._profile.get_profile_data() self.suite = get_suite(self.conn, profile) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) self.installer.log = self.log self.installer.familydata = self.familydata self.installer.profiledata = self.profiledata self.traitparent = TraitParent(self.conn, self.suite) self.log.info('profile set to %s' % profile) def get_profile_data(self): return self.env.ProfileData() def set_logpath(self, logpath): Installer.set_logpath(self, logpath) if hasattr(self, 'installer'): self.installer.set_logpath(logpath) def make_traitlist_orig(self): traitparent = TraitParent(self.conn, self.suite) profile_traits = [x.trait for x in self.profiletrait.trait_rows()] all_traits = list(self.traitparent.get_traitset(profile_traits)) traitlist = [] while len(profile_traits): profile_traits_prepended = False trait = profile_traits[0] traitparent.set_trait(trait) parents = [r.parent for r in traitparent.parents()] for p in parents: if not profile_traits_prepended and p not in traitlist: profile_traits = [p] + profile_traits profile_traits_prepended = True self.log.info('profile_traits prepended with %s' % p) if not profile_traits_prepended: traitlist.append(trait) del profile_traits[0] self.log.info('%s %s' % (str(traitlist), profile_traits)) return traitlist def make_traitlist(self): tp = TraitParent(self.conn, self.suite) listed = [x.trait for x in self.profiletrait.trait_rows()] all = list(self.traitparent.get_traitset(listed)) setfun = tp.set_trait parfun = tp.parents log = self.log return make_deplist(listed, all, setfun, parfun, log) def process(self): traits = self.make_traitlist() self.processed = [] for trait in traits: self.process_trait(trait) self.log.info('currently processed %s' % ','.join(self.processed)) self.log.info('all traits processed for profile %s' % self.profile) self.log.info('------------------------------------') def process_trait(self, trait): self.traitparent.set_trait(trait) self.installer.set_trait(trait) parents = [r.parent for r in self.traitparent.parents()] for p in parents: if p not in self.processed: raise UnbornError self.log.info('processing trait %s' % trait) self.installer.process() self.processed.append(trait) self.log.info('processed: %s' % ', '.join(self.processed)) def set_template_path(self, path): self.installer.set_template_path(path) def set_target(self, target, update=False): Installer.set_target(self, target) self.installer.set_target(target) if update: os.system(self.command('apt-get update')) def install_kernel(self, package): os.system(self.command('touch /boot/vmlinuz-fake')) os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz')) os.system(self.command('apt-get -y install %s' % package)) print 'kernel %s installed' % package
class TraitTemplateBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(_MODTRAIT, self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.traits = Traits(self.conn, suite) self.trait_selection = '_all_traits_' self.reset_rows() self.cfg = PaellaConfig() self._parents = TraitParent(self.conn, suite) self.cursor = StatementCursor(self.conn) self.template_path = '/nowhere' self.tarball_path = self.cfg.get('management_gui', 'bkuptarball_path') self.suite = suite def modify_trait(self, menuitem, action): if action == 'hello': dialogs.Message('hello') elif action in ['import', 'update']: filesel = select_a_file(action, self.tarball_path + '/', self.select_trait_tarball) elif action in ['updatedir', 'exportdir', 'importdir']: filesel = select_a_file(action, self.tarball_path + '/', self.select_traitdir) elif action == 'export': try: trait = self.listbox.get_selected_data()[0].trait #self.pages[trait].extract_packages() self.select_export_path(trait) except IndexError: dialogs.Message('no trait selected') elif action == 'extract': try: trait = self.listbox.get_selected_data()[0].trait self.pages[trait].extract_packages() except IndexError: dialogs.Message('no trait selected') def reset_rows(self): if self.trait_selection == '_all_traits_': rows = self.traits.select(fields=['trait']) self.set_rows(rows) else: clause = Eq('profile', self.trait_selection) rows = self.cursor.select(fields=['trait'], table='profile_trait', clause=clause) ptraits = [x.trait for x in rows] traits = self._parents.get_traitset(ptraits) self.set_rows(list(traits), [self.trait_selection]) self.set_row_select(self.trait_selected) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0][0] self.select_trait(trait) def select_trait(self, trait): if trait not in self.pages: newpage = TemplateBrowser(self.conn, self.traits.suite, trait) self.append_page(newpage, trait) self.set_current_page(trait) def set_suite(self, suite): self.suite = suite self.traits.set_suite(suite) for page in self.pages: self.remove_page(page) self.reset_rows() def select_traitdir(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() if not isdir(path): path = dirname(path) if not isdir(path): raise Error, '%s not found' % path if action in ['updatedir', 'importdir']: if action == 'updatedir': tcmd = 'update' elif action == 'importdir': tcmd = 'import' traits = [t.trait for t in self.traits.select()] if tcmd == 'update': ls = [f for f in os.listdir(path) if f[-4:] == '.tar' and f[:-4] in traits] for f in ls: self.importupdate(join(path, f), tcmd) elif tcmd == 'import': ls = [f for f in os.listdir(path) if f[-4:] == '.tar'] traits = [t[:-4] for t in ls] while len(traits): trait = traits[0] try: self.importupdate(join(path, trait + '.tar'), tcmd) except UnbornError: traits.append(trait) del traits[0] print 'processed', trait elif action == 'exportdir': self.select_export_path('_all_traits_') def select_trait_tarball(self, button, filesel): path = filesel.get_filename() action = filesel.get_data('action') filesel.destroy() self.importupdate(path, action) def importupdate(self, path, action): tarball = TraitTarFile(path) trait = tarball.get_trait() traitdb = Trait(self.conn, self.suite) if action == 'import': traitdb.insert_trait(path, suite=self.suite) for info in tarball: if info.name[:10] == 'templates/': #tarball.extract(info, template_path) pass self.reset_rows() def select_export_path(self, trait): filesel = select_a_file(trait, self.tarball_path + '/', self.export_path_selected) def export_path_selected(self, button, filesel): trait = filesel.get_data('action') path = dirname(filesel.get_filename()) filesel.destroy() if trait == '_all_traits_': traits = [t.trait for t in self.traits.select()] for t in traits: self.export_trait(t, path) else: self.export_trait(trait, path) def export_trait(self, trait, path=None): if path is None: path = self.tarball_path tt = TraitTemplate(self.conn, self.suite) tt.set_trait(trait) backup_trait(self.conn, self.suite, trait, path) dialogs.Message('%s exported to %s' % (trait, path))
class InstallerTools(object): def __init__(self): object.__init__(self) self.cfg = PaellaConfig() self.conn = PaellaConnection() self.profile = os.environ['PAELLA_PROFILE'] self.target = os.environ['PAELLA_TARGET'] self.machine = None self.trait = None self.suite = get_suite(self.conn, self.profile) self.pr = Profile(self.conn) self.pr.set_profile(self.profile) self.traitlist = self.pr.make_traitlist() self.pe = ProfileEnvironment(self.conn, self.profile) self.tp = TraitParent(self.conn, self.suite) self.fm = Family(self.conn) self.tr = Trait(self.conn, self.suite) self.families = list( self.fm.get_related_families(self.pr.get_families())) self._envv = None self.default = DefaultEnvironment(self.conn) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) if os.environ.has_key('PAELLA_MACHINE'): self.machine = os.environ['PAELLA_MACHINE'] if os.environ.has_key('PAELLA_TRAIT'): self.set_trait(os.environ['PAELLA_TRAIT']) def env(self): env = RefDict(self.tp.Environment()) env.update(self.pr.get_family_data()) env.update(self.pr.get_profile_data()) return env def set_trait(self, trait): self.trait = trait self.tp.set_trait(trait) self.tr.set_trait(trait) self.parents = self.tr.parents() self._envv = self.env() self.installer.set_trait(trait) self.packages = self.installer.traitpackage.packages() self.templates = self.installer.traittemplate.templates() def get(self, key): if self._envv is None: raise Error, 'need to set trait first' return self._envv.dereference(key) def install_modules(self, name): modules = str2list(self.get(name)) print 'installing modules', modules, 'to %s/etc/modules' % self.target setup_modules(self.target, modules) def remove_packages(self, packages=None): if packages is None: packages = self.packages if len(packages): if hasattr(packages[0], 'package'): packages = [p.package for p in packages] package_list = ' '.join(packages) command = 'apt-get -y remove %s' % package_list self.installer.run('remove', command, proc=True)
self.parents = self.tr.parents() self._envv = self.env() self.installer.set_trait(trait) self.packages = self.installer.traitpackage.packages() self.templates = self.installer.traittemplate.templates() def get(self, key): if self._envv is None: raise Error, 'need to set trait first' return self._envv.dereference(key) def install_modules(self, name): modules = str2list(self.get(name)) print 'installing modules', modules, 'to %s/etc/modules' % self.target setup_modules(self.target, modules) def remove_packages(self, packages=None): if packages is None: packages = self.packages if len(packages): if hasattr(packages[0], 'package'): packages = [p.package for p in packages] package_list = ' '.join(packages) command = 'apt-get -y remove %s' % package_list self.installer.run('remove', command, proc=True) if __name__ == '__main__': conn = PaellaConnection() tp = TraitParent(conn, 'gunny')
class ProfileInstaller(Installer): def __init__(self, conn, cfg): Installer.__init__(self, conn, cfg) self.profiletrait = ProfileTrait(self.conn) self.profile = None self.installer = None self.cfg = cfg self.log.info('profile installer initialized') def set_profile(self, profile): self.profile = profile os.environ['PAELLA_PROFILE'] = profile self.profiletrait.set_profile(profile) self.traits = self.profiletrait.trait_rows() self.env = ProfileEnvironment(self.conn, self.profile) self.profiledata = self.get_profile_data() self.suite = get_suite(self.conn, profile) self.installer = TraitInstaller(self.conn, self.suite, self.cfg) self.installer.log = self.log self.installer.profiledata = self.profiledata self.traitparent = TraitParent(self.conn, self.suite) self.log.info('profile set to %s' % profile) def get_profile_data(self): return self.env.ProfileData() def set_logpath(self, logpath): Installer.set_logpath(self, logpath) if hasattr(self, 'installer'): self.installer.set_logpath(logpath) def make_traitlist(self): traitparent = TraitParent(self.conn, self.suite) profile_traits = [x.trait for x in self.profiletrait.trait_rows()] all_traits = list(self.traitparent.get_traitset(profile_traits)) traitlist = [] while len(profile_traits): profile_traits_prepended = False trait = profile_traits[0] traitparent.set_trait(trait) parents = [r.parent for r in traitparent.parents()] for p in parents: if not profile_traits_prepended and p not in traitlist: profile_traits = [p] + profile_traits profile_traits_prepended = True self.log.info('profile_traits prepended with %s' % p) if not profile_traits_prepended: traitlist.append(trait) del profile_traits[0] self.log.info('%s %s' % (str(traitlist), profile_traits)) return traitlist def process(self): traits = self.make_traitlist() self.processed = [] for trait in traits: self.process_trait(trait) self.log.info('currently processed %s' % ','.join(self.processed)) self.log.info('all traits processed for profile %s' % self.profile) self.log.info('------------------------------------') def process_trait(self, trait): self.traitparent.set_trait(trait) self.installer.set_trait(trait) parents = [r.parent for r in self.traitparent.parents()] for p in parents: if p not in self.processed: raise UnbornError self.log.info('processing trait %s' % trait) self.installer.process() self.processed.append(trait) self.log.info('processed: %s' % ', '.join(self.processed)) def set_template_path(self, path): self.installer.set_template_path(path) def set_target(self, target, update=False): Installer.set_target(self, target) self.installer.set_target(target) if update: os.system(self.command('apt-get update')) def install_kernel(self, package): os.system(self.command('touch /boot/vmlinuz-fake')) os.system(self.command('ln -s boot/vmlinuz-fake vmlinuz')) os.system(self.command('apt-get -y install %s' % package)) print 'kernel %s installed' % package
def __rebuild_modules__(self): del self[:] for line in self.lines: if line and line[0] != '#': list.append(self, line) def append(self, module): if module not in self: self.lines.append(module) self.__rebuild_modules__() def write(self, path=None): if path is None: path = self.path mfile = file(path, 'w') mfile.write('\n'.join(self.lines) + '\n') mfile.close() if __name__ == '__main__': from useless.db.midlevel import StatementCursor from useless.db.midlevel import Environment, TableDict c = PaellaConnection() tp = TraitParent(c, 'woody') pp = TraitPackage(c, 'woody') ct = ConfigTemplate() path = '/tmp/spam.db' db = bsddb.btopen('path', 'c') p = Parser('var-table.csv')
def get_profile_packages(conn, suite, profile): traits = get_traits(conn, profile) tp = TraitParent(conn, suite) pp = TraitPackage(conn, suite) packages = [p.package for p in pp.all_packages(traits, tp)] return packages