def get_owner(self): ''' Prompts user for overlay owner info and then appends the values to the overlay being created. ''' self.overlay['owner'] = [] self.output.notice('') msg = 'How many people own this overlay?: ' owner_amount = int(get_input(msg)) for i in range(1, owner_amount + 1): owner = {} extra = '' if owner_amount > 1: extra = '[%(i)s]\'s' % {'i': str(i)} owner['name'] = get_input('Define owner%(extra)s name: '\ % {'extra': extra}) owner['email'] = get_input('Define owner%(extra)s email: '\ % {'extra': extra}) self.overlay['owner'].append(owner) self.output.notice('')
def get_owner(self): ''' Prompts user for overlay owner info and then appends the values to the overlay being created. ''' self.output.notice('') self.overlay['owner_name'] = get_input('Define owner name: ') self.overlay['owner_email'] = get_input('Define owner email: ') self.output.notice('')
def get_owner(self): """ Prompts user for overlay owner info and then appends the values to the overlay being created. """ self.output.notice("") self.overlay["owner_name"] = get_input("Define owner name: ") self.overlay["owner_email"] = get_input("Define owner email: ") self.output.notice("")
def get_source(self): ''' Prompts user for possible overlay source information such as type, url, and branch and then appends the values to the overlay being created. ''' ovl_type = None if self.auto_complete: source_amount = 1 else: msg = 'How many different sources, protocols, or mirrors exist '\ 'for this overlay?: ' source_amount = int(get_input(msg)) self.overlay['source'] = [] for i in range(1, source_amount + 1): sources = [] correct = False extra = '' if source_amount > 1: extra = '[%(i)s]\'s' % {'i': str(i)} msg = 'Define source%(extra)s URL: ' % {'extra': extra} sources.append(get_input(msg)) ovl_type = self.guess_overlay_type(sources[0]) if ovl_type: msg = 'Is "%(type)s" the correct overlay type?: '\ % ({'type': ovl_type}) correct = get_ans(msg) while not ovl_type or not correct: msg = 'Please provide overlay type: ' ovl_type = self.check_overlay_type(\ get_input(msg, color='yellow')) correct = True sources.append(ovl_type) if 'branch' in self.required: msg = 'Define source%(extra)s branch (if applicable): '\ % {'extra': extra} sources.append(get_input(msg)) else: sources.append('') if self.auto_complete: sources = self._set_additional_info(sources) for source in sources: self.overlay['source'].append(source) else: self.overlay['source'].append(sources) self.output.notice('')
def get_name(self): """ Prompts user for the overlay name and updates the overlay dict. """ name = get_input("Define overlay name: ") if not self.sudo: while name in self.overlays_available: msg = "!!! Overlay name already defined in list of installed" " overlays." self.output.warn(msg) msg = "Please specify a different overlay name: " name = get_input(msg, color="yellow") self.overlay["name"] = name
def get_name(self): ''' Prompts user for the overlay name and updates the overlay dict. ''' name = get_input('Define overlay name: ') if not self.sudo: while name in self.overlays_available: msg = '!!! Overlay name already defined in list of installed'\ ' overlays.' self.output.warn(msg) msg = 'Please specify a different overlay name: ' name = get_input(msg, color='yellow') self.overlay['name'] = name
def get_feeds(self): ''' Prompts user for any overlay RSS feeds and updates overlay dict with values. ''' msg = 'How many RSS feeds exist for this overlay?: ' feed_amount = int(get_input(msg)) feeds = [] for i in range(1, feed_amount + 1): if feed_amount > 1: msg = 'Define overlay feed[%(i)s]: ' % ({'i': str(i)}) feeds.append(get_input(msg)) else: feeds.append(get_input('Define overlay feed: ')) self.overlay['feeds'] = feeds self.output.notice('')
def get_feed(self): ''' Prompts user for any overlay RSS feeds and updates overlay dict with values. ''' msg = 'How many RSS feeds exist for this overlay?: ' feed_amount = int(get_input(msg)) feeds = [] for i in range(1, feed_amount + 1): extra = '' if feed_amount > 1: extra = '[%(i)s]' % {'i': str(i)} feeds.append(get_input('Define overlay%(extra)s feed: '\ % {'extra': extra})) self.overlay['feed'] = feeds self.output.notice('')
def get_feed(self): """ Prompts user for any overlay RSS feeds and updates overlay dict with values. """ msg = "How many RSS feeds exist for this overlay?: " feed_amount = int(get_input(msg)) feeds = [] for i in range(1, feed_amount + 1): if feed_amount > 1: msg = "Define overlay feed[%(i)s]: " % ({"i": str(i)}) feeds.append(get_input(msg)) else: feeds.append(get_input("Define overlay feed: ")) self.overlay["feed"] = feeds self.output.notice("")
def write(self, destination): ''' Writes overlay file to desired location. @params destination: path & file to write xml to. @rtype bool: reflects success or failure to write xml. ''' if not destination: filepath = self.config.get_option('overlay_defs') if self.sudo: filepath = get_input('Desired file destination dir: ') filename = get_input('Desired overlay file name: ') if not filename.endswith('.xml'): filename += ".xml" if not filepath.endswith(os.path.sep): filepath += os.path.sep destination = filepath + filename self.tree = ET.Element('repositories', version='1.1', encoding=_UNICODE) if os.path.isfile(destination): self.read(destination) self._sort_to_tree() indent(self.tree) self.tree = ET.ElementTree(self.tree) try: with fileopen(destination, 'w') as xml: self.tree.write(xml, encoding=_UNICODE) msg = 'Successfully wrote repo(s) to: %(path)s'\ % ({'path': destination}) self.output.info(msg) return True except IOError as e: raise Exception("Writing XML failed: %(error)s" % ({'error': e}))
def get_component(self, component, msg): ''' Sets overlay component value. @params component: (str) component to be set @params msg: (str) prompt message for component ''' if component not in ('branch', 'type'): if component in ('description', 'feed', 'name', 'owner', 'source'): getattr(self, 'get_%(comp)s' % ({'comp': component}))() else: self.overlay[component] = get_input(msg)
def get_component(self, component, msg): """ Sets overlay component value. @params component: (str) component to be set @params msg: (str) prompt message for component """ if component not in ("branch", "type"): if component in ("description", "feed", "name", "owner", "source"): getattr(self, "get_%(comp)s" % ({"comp": component}))() else: self.overlay[component] = get_input(msg)
def get_description(self): ''' Prompts user for an overlay's description(s) and updates overlay dict with value(s). ''' #TODO: Currently a "stub" function. Add multiple description # field support later down the road. descriptions = [] desc = get_input('Define overlay\'s description: ') descriptions.append(desc) self.overlay['description'] = descriptions
def write(self, destination): """ Writes overlay file to desired location. @params destination: path & file to write xml to. @rtype bool: reflects success or failure to write xml. """ if not destination: filepath = self.config.get_option("overlay_defs") if self.sudo: filepath = get_input("Desired file destination dir: ") filename = get_input("Desired overlay file name: ") if not filename.endswith(".xml"): filename += ".xml" if not filepath.endswith(os.path.sep): filepath += os.path.sep destination = filepath + filename self.tree = ET.Element("repositories", version="1.1", encoding=_UNICODE) if os.path.isfile(destination): self.read(destination) self._sort_to_tree() indent(self.tree) self.tree = ET.ElementTree(self.tree) try: with fileopen(destination, "w") as xml: self.tree.write(xml, encoding=_UNICODE) msg = "Successfully wrote repo(s) to: %(path)s" % ({"path": destination}) self.output.info(msg) return True except IOError as e: raise Exception("Writing XML failed: %(error)s" % ({"error": e}))
def __call__(self, overlay_package=None, path=None): if not overlay_package: self.args_parser() options = {} for key in vars(self.args): options[key] = vars(self.args)[key] self.config = OptionConfig(options=options) reload_config(self.config) self.auto_complete = False self.list_info = self.config.get_option('list_autocomplete') self.no_extra = self.config.get_option('no_extra') self.sudo = self.config.get_option('sudo') if self.list_info: self.list_templates() if self.args.set_autocomplete: if 'ALL' in self.args.set_autocomplete: self.templates = AUTOCOMPLETE_TEMPLATE.keys() self.auto_complete = True else: self.templates = self.args.set_autocomplete self.auto_complete = True msg = 'How many overlays would you like to create?: ' for x in range(1, int(get_input(msg)) + 1): self.output.notice('') self.output.info('Overlay #%(x)s: ' % ({'x': str(x)})) self.output.info('~~~~~~~~~~~~~') self.required = copy.deepcopy(COMPONENT_DEFAULTS) if not self.no_extra: self.output.notice('') self.update_required() self.output.notice('') self.get_overlay_components() ovl = Overlay.Overlay(config=self.config, ovl_dict=self.overlay, ignore=1) self.overlays.append((self.overlay['name'], ovl)) else: ovl_name, ovl = overlay_package self.overlays.append((ovl_name, ovl)) result = self.write(path) return result
def __call__(self, overlay_package=None, path=None): if not overlay_package: self.args_parser() options = {} for key in vars(self.args): options[key] = vars(self.args)[key] self.config = OptionConfig(options=options) reload_config(self.config) self.auto_complete = False self.list_info = self.config.get_option('list_autocomplete') self.no_extra = self.config.get_option('no_extra') self.sudo = self.config.get_option('sudo') if self.list_info: self.list_templates() if self.args.set_autocomplete: if 'ALL' in self.args.set_autocomplete: self.templates = AUTOCOMPLETE_TEMPLATE.keys() self.auto_complete = True else: self.templates = self.args.set_autocomplete self.auto_complete = True msg = 'How many overlays would you like to create?: ' for x in range(1, int(get_input(msg))+1): self.output.notice('') self.output.info('Overlay #%(x)s: ' % ({'x': str(x)})) self.output.info('~~~~~~~~~~~~~') self.required = copy.deepcopy(COMPONENT_DEFAULTS) if not self.no_extra: self.output.notice('') self.update_required() self.output.notice('') self.get_overlay_components() ovl = Overlay.Overlay(config=self.config, ovl_dict=self.overlay, ignore=1) self.overlays.append((self.overlay['name'], ovl)) else: ovl_name, ovl = overlay_package self.overlays.append((ovl_name, ovl)) result = self.write(path) return result
def get_source(self): """ Prompts user for possible overlay source information such as type, url, and branch and then appends the values to the overlay being created. """ ovl_type = None if self.auto_complete: source_amount = 1 else: msg = "How many different sources, protocols, or mirrors exist " "for this overlay?: " source_amount = int(get_input(msg)) self.overlay["source"] = [] for i in range(1, source_amount + 1): sources = [] correct = False if source_amount > 1: msg = "Define source[%(i)s]'s URL: " % ({"i": str(i)}) sources.append(get_input(msg)) ovl_type = self.guess_overlay_type(sources[0]) if ovl_type: msg = 'Is "%(type)s" the correct overlay type?: ' % ({"type": ovl_type}) correct = get_ans(msg) while not ovl_type or not correct: msg = "Please provide overlay type: " ovl_type = self.check_overlay_type(get_input(msg, color="yellow")) correct = True sources.append(ovl_type) if "branch" in self.required: msg = "Define source[%(i)s]'s branch (if applicable): " % ({"i": str(i)}) sources.append(get_input(msg)) else: sources.append("") else: sources.append(get_input("Define source URL: ")) ovl_type = self.guess_overlay_type(sources[0]) if ovl_type: msg = "Is %(type)s the correct overlay type?: " % ({"type": ovl_type}) correct = get_ans(msg) while not ovl_type or not correct: msg = "Please provide overlay type: " ovl_type = self.check_overlay_type(get_input(msg, color="yellow")) correct = True sources.append(ovl_type) if "branch" in self.required: msg = "Define source branch (if applicable): " sources.append(get_input(msg)) else: sources.append("") if self.auto_complete: sources = self._set_additional_info(sources) for source in sources: self.overlay["source"].append(source) else: self.overlay["source"].append(sources) self.output.notice("")