def __init__(self, daemon, config, db): self.configfile = config self.mtime = os.path.getmtime(config) config = ConfigParser(config) IniConfig.__init__(self, config, 'repo') self.logger = logging.getLogger('golem.repo.' + self.name) self.logger.info("Parsing configuration for %s" % self.name) self.path = os.path.join(daemon.repo_dir, self.name) self.repo_path = os.path.join(self.path, self.name + '.git') self.artefact_path = os.path.join(self.path, 'artefacts') self.shell = whelk.Shell(output_callback=OutputLogger(self.logger), run_callback=RunLogger(self.logger), cwd=self.repo_path) if hasattr(self, 'reflog_url'): self.reflogtype = 'http' self.reflogurl = self.reflog_url elif re.match('^https?://', self.upstream): self.reflogtype = 'http' self.reflogurl = self.upstream + '/logs/%REF%' elif self.upstream.startswith('file://'): self.reflogtype = 'file' self.upstream_path = self.upstream[7:] if self.git('config', 'core.bare', cwd=self.upstream_path).stdout.strip() != 'false': self.upstream_path = os.path.join(self.upstream_path, '.git') elif ':' in self.upstream: self.reflogtype = 'ssh' else: self.reflogtype = 'file' self.upstream_path = self.upstream if self.shell.git('config', 'core.bare', cwd=self.upstream).stdout.strip() != 'false': self.upstream_path = os.path.join(self.upstream_path, '.git') if re.match('^([a-z]+://|git@)github.com', self.upstream): self.reflogtype = 'github' if not self.reflogtype: raise GolemError("Don't know how to fetch reflogs for %s" % self.name) for section in config.sections(): if section.startswith('action:'): action = section[7:] self.logger.info(" Adding action %s" % action) self.actions[action] = Action(config, section) self.actions[action].artefact_path = os.path.join(self.artefact_path, action) self.actions[action].daemon = daemon self.actions[action].repo_name = self.name elif section.startswith('notify:'): nf = section[7:] self.logger.info(" Adding notifier %s" % nf) self.notifiers[nf] = Notifier(config, section) self.notifiers[nf].daemon = daemon self.notifiers[nf].repo_name = self.name changed = True while changed: changed = False for action in self.actions: for req in self.actions[action].requires: req = req[7:] # Backlog is "inherited" from the dependencies if self.actions[req].backlog < self.actions[action].backlog: changed = True self.actions[action].backlog = self.actions[req].backlog # Same for branches and tags. Intersection of all parents if self.actions[req].branches and not self.actions[action].branches: changed = True self.actions[action].branches = copy(self.actions[req].branches) elif self.actions[req].branches: for branch in self.actions[action].branches[:]: if branch not in self.actions[req].branches: changed = True self.actions[action].branches.remove(branch) if self.actions[req].tags and not self.actions[action].tags: changed = True self.actions[action].tags = copy(self.actions[req].tags) elif self.actions[req].tags: for tag in self.actions[action].tags[:]: if tag not in self.actions[req].tags: changed = True self.actions[action].tags.remove(tag) if not daemon.dummy: self.create_dirs() _r = golem.db.repository self.id = db.execute(sql.select([_r.c.id]).where(_r.c.name==self.name)).fetchone() self.id = self.id.id if self.id else db.execute(_r.insert().values(name=self.name)).inserted_primary_key[0]
def __init__(self, *args, **kwargs): super(Daemon, self).__init__(*args, **kwargs) p = ConfigParser(os.path.join(os.path.expanduser('~'), '.pause')) self.username = p.get('pause', 'username') self.password = p.get('pause', 'password')