def ensure_environment(envname, default, modules=[], hostgroups=[], common=[], parser=None): environment = {'notifications': '*****@*****.**'} if default is not None: environment['default'] = default if len(modules) + len(hostgroups) + len(common) > 0: environment['overrides'] = {} if len(modules) >= 1: environment['overrides']['modules'] = {} for module in modules: name, override = module.split(':') environment['overrides']['modules'][name] = override if len(hostgroups) >= 1: environment['overrides']['hostgroups'] = {} for hostgroup in hostgroups: name, override = hostgroup.split(':') environment['overrides']['hostgroups'][name] = override if parser: environment['parser'] = parser settings = Settings() environment_file = open("%s/%s.yaml" % (settings.ENV_METADATADIR, envname), 'w+') yaml.dump(environment, environment_file, default_flow_style=False) environment_file.close()
def _expand_clones(partition, name, inventory, inventory_lock, new_refs, moved_refs, deleted_refs): settings = Settings() bare_path = _compose_bare_repository_path(name, partition) if new_refs: logging.debug("Processing new refs of %s/%s (%s)...", partition, name, new_refs) for refname in new_refs: clone_path = _compose_clone_repository_path(name, partition, refname) logging.info("Populating new ref '%s'", clone_path) try: if ref_is_commit(refname): commit_id = refname.replace(settings.HASHPREFIX, '') logging.debug("Will create a clone pointing to '%s'", commit_id) git.clone(clone_path, "%s" % bare_path, shared=True) git.reset(clone_path, commit_id, hard=True) else: git.clone(clone_path, "%s" % bare_path, branch=refname) # Needs reset so the proxy notices about the change on the mutable # http://docs.python.org/2.7/library/multiprocessing.html#managers # Locking on the assignment is guarateed by the library, but # additional locking is needed as A = A + 1 is a critical section. if inventory_lock: inventory_lock.acquire() inventory[name] += [refname] if inventory_lock: inventory_lock.release() except JensGitError, error: if os.path.isdir(clone_path): shutil.rmtree(clone_path) logging.error("Unable to create clone '%s' (%s)", clone_path, error)
def refresh_repositories(hints=None): settings = Settings() try: logging.debug("Reading metadata from %s", settings.REPO_METADATA) definition = yaml.load(open(settings.REPO_METADATA, 'r')) except Exception, error: # fixme raise JensRepositoriesError("Unable to parse %s (%s)", settings.REPO_METADATA, error)
def del_repository(partition, name): settings = Settings() repositories_file = open(settings.REPO_METADATA, 'r') data = yaml.load(repositories_file) repositories_file.close() del data['repositories'][partition][name] repositories_file = open(settings.REPO_METADATA, 'w+') yaml.dump(data, repositories_file, default_flow_style=False) repositories_file.close()