def updateconf(opts, canari_conf): ld = os.getcwd() os.chdir(os.path.dirname(canari_conf)) config = CanariConfigParser() config.read(canari_conf) configs = config['default/configs'] packages = config['remote/packages'] conf = '%s.conf' % opts.package if isinstance(configs, basestring): configs = [configs] if configs else [] if isinstance(packages, basestring): packages = [packages] if packages else [] if conf not in configs: print ('Updating %s...' % canari_conf) configs.append(conf) config['default/configs'] = ','.join(configs) if opts.package not in packages: packages.append(opts.package) config['remote/packages'] = ','.join(packages) config.write(file(canari_conf, mode='wb')) os.chdir(ld)
def init_pkg(): conf = '.canari' for i in range(0, 5): if path.exists(conf): c = CanariConfigParser() c.read(conf) return { 'author' : c['metadata/author'], 'email' : c['metadata/email'], 'maintainer' : c['metadata/maintainer'], 'project' : c['metadata/project'], 'year' : datetime.now().year, 'dir' : getcwd() } conf = '..%s%s' % (sep, conf) return { 'author' : '', 'email' : '', 'maintainer' : '', 'project' : '', 'year' : datetime.now().year }
def updateconf(opts, canari_conf): ld = os.getcwd() os.chdir(os.path.dirname(canari_conf)) config = CanariConfigParser() config.read(canari_conf) configs = config['default/configs'] packages = config['remote/packages'] conf = '%s.conf' % opts.package if isinstance(configs, basestring): configs = [configs] if configs else [] if isinstance(packages, basestring): packages = [packages] if packages else [] if conf in configs: print('Updating %s...' % canari_conf) configs.remove(conf) config['default/configs'] = ','.join(configs) if opts.package in packages: packages.remove(opts.package) config['remote/packages'] = ','.join(packages) config.write(file(canari_conf, mode='wb')) os.chdir(ld)
def init_pkg(): root = project_root() if root is not None: conf = os.path.join(root, '.canari') if os.path.exists(conf): c = CanariConfigParser() c.read(conf) return { 'author': c['metadata/author'], 'email': c['metadata/email'], 'maintainer': c['metadata/maintainer'], 'project': c['metadata/project'], 'year': datetime.now().year } return { 'author': '', 'email': '', 'maintainer': '', 'project': '', 'year': datetime.now().year }
def _update_config(self, canari_config, load=True, remote=False): ld = os.getcwd() os.chdir(os.path.dirname(canari_config)) config = CanariConfigParser() config.read(canari_config) configs = config['default/configs'] packages = config['remote/packages'] if isinstance(configs, basestring): configs = [configs] if configs else [] if isinstance(packages, basestring): packages = [packages] if packages else [] if load: if self.config_file not in configs: print ('Updating %s...' % canari_config) configs.append(self.config_file) config['default/configs'] = ','.join(configs) if self.name not in packages and remote: packages.append(self.name) config['remote/packages'] = ','.join(packages) else: if self.config_file in configs: print ('Updating %s...' % canari_config) configs.remove(self.config_file) config['default/configs'] = ','.join(configs) if self.name in packages and remote: packages.remove(self.name) config['remote/packages'] = ','.join(packages) config.write(file(canari_config, mode='wb')) os.chdir(ld)
def _update_config(self, canari_config, load=True, remote=False): ld = os.getcwd() os.chdir(os.path.dirname(canari_config)) config = CanariConfigParser() config.read(canari_config) configs = config['default/configs'] packages = config['remote/packages'] if isinstance(configs, basestring): configs = [configs] if configs else [] if isinstance(packages, basestring): packages = [packages] if packages else [] if load: if self.config_file not in configs: print('Updating %s...' % canari_config) configs.append(self.config_file) config['default/configs'] = ','.join(configs) if self.name not in packages and remote: packages.append(self.name) config['remote/packages'] = ','.join(packages) else: if self.config_file in configs: print('Updating %s...' % canari_config) configs.remove(self.config_file) config['default/configs'] = ','.join(configs) if self.name in packages and remote: packages.remove(self.name) config['remote/packages'] = ','.join(packages) config.write(file(canari_config, mode='wb')) os.chdir(ld)
def _update_config(self, canari_config, load=True, remote=False): with PushDir(os.path.dirname(canari_config)): config = CanariConfigParser() config.read(canari_config) configs_option = OPTION_REMOTE_CONFIGS if remote else OPTION_LOCAL_CONFIGS config_section = SECTION_REMOTE if remote else SECTION_LOCAL if configs_option not in config: if config_section not in config: config.add_section(config_section) config[configs_option] = '' configs = config.get_as_list(configs_option) if load: if self.config_file not in configs: print ('Updating %s...' % canari_config) configs.append(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name not in packages: packages.append(self.name) config[OPTION_REMOTE_PACKAGES] = packages else: if self.config_file in configs: print ('Updating %s...' % canari_config) configs.remove(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name in packages: packages.remove(self.name) config[OPTION_REMOTE_PACKAGES] = packages config.write(file(canari_config, mode='wb'))
def _update_config(self, canari_config, load=True, remote=False, **kwargs): with PushDir(os.path.dirname(canari_config)): config = CanariConfigParser() config.read(canari_config) configs_option = OPTION_REMOTE_CONFIGS if remote else OPTION_LOCAL_CONFIGS config_section = SECTION_REMOTE if remote else SECTION_LOCAL if configs_option not in config: if config_section not in config: config.add_section(config_section) config[configs_option] = '' configs = config.get_as_list(configs_option) if load: for (k, v) in kwargs.get('additional_options', {}).items(): config['.'.join([config_section, k])] = v if self.config_file not in configs: print('Updating %s...' % canari_config, file=sys.stderr) configs.append(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name not in packages: packages.append(self.name) config[OPTION_REMOTE_PACKAGES] = packages else: if self.config_file in configs: print('Updating %s...' % canari_config, file=sys.stderr) configs.remove(self.config_file) config[configs_option] = configs if remote: packages = config.get_as_list(OPTION_REMOTE_PACKAGES) if self.name in packages: packages.remove(self.name) config[OPTION_REMOTE_PACKAGES] = packages config.write(open(canari_config, mode='w'))