Ejemplo n.º 1
0
 def prepare(self):
     self.temp_dir_root = tempfile.mkdtemp(
         prefix='sphinx_docs_', dir=get_tmpdir())
     if self.config['checkout_root']:
         tree_hash = _tree_hash(self.project_id, '')
     else:
         tree_hash = _tree_hash(self.project_id, self.dir)
     if not tree_hash or not self.has_content():
         warn("No docs directory in project repo at HEAD for builder %s" %
              self.builder)
         return False, 'no_doc_dir_found'
     mc.set(LAST_TREE_HASH_MC_KEY % (self.project_id,
            self.builder), tree_hash)
     try:
         os.makedirs(self.docs_dir)
     except OSError:
         pass
     ret, msg = _export_docs_tree(
         self.project_id, tree_hash, self.temp_dir_root)
     if not ret:
         return False, msg
     if self.config['checkout_root']:
         self.temp_dir = os.path.join(self.temp_dir_root, self.dir)
     else:
         self.temp_dir = self.temp_dir_root
     return True, 'success'
Ejemplo n.º 2
0
def get_release(repository):
    '''get latest successed release info

    return: a dict with keys {annotate, changesets, message, first_rev,
                              last_rev, pre_release_rev, status,
                              project_source, release_manger, release_time,
                              url}
    '''
    if not repository.startswith('http:'):
        repository = 'http://code.dapps.douban.com/' + repository
    if not repository.endswith('.git'):
        repository = repository + '.git'

    key = MC_KEY_REPOSITORY_RELEASE % repository
    info = mc.get(key)

    if info is not None:
        return info

    try:
        info = fetch_release(repository)
        mc.set(key, info, ONE_DAY)
        return info
    except:
        return {}
Ejemplo n.º 3
0
 def get_or_create(self, key, creation_function, **kw):
     r = mc.get(key)
     if r is None:
         r = creation_function()
         expiretime = kw.get("timeout", ONE_HOUR)
         mc.set(key, r, expiretime)
     return r
Ejemplo n.º 4
0
 def get_or_create(self, key, creation_function, **kw):
     r = mc.get(key)
     if r is None:
         r = creation_function()
         expiretime = kw.get('timeout', ONE_HOUR)
         mc.set(key, r, expiretime)
     return r
Ejemplo n.º 5
0
def get_release(repository):
    '''get latest successed release info

    return: a dict with keys {annotate, changesets, message, first_rev,
                              last_rev, pre_release_rev, status,
                              project_source, release_manger, release_time,
                              url}
    '''
    if not repository.startswith('http:'):
        repository = 'http://code.dapps.douban.com/' + repository
    if not repository.endswith('.git'):
        repository = repository + '.git'

    key = MC_KEY_REPOSITORY_RELEASE % repository
    info = mc.get(key)

    if info is not None:
        return info

    try:
        info = fetch_release(repository)
        mc.set(key, info, ONE_DAY)
        return info
    except:
        return {}
Ejemplo n.º 6
0
    def prepare(self):
        self.temp_dir_root = tempfile.mkdtemp(prefix='sphinx_docs_',
                                              dir=get_tmpdir())
        if self.config['checkout_root']:
            tree_hash = _tree_hash(self.project_id, '')
        else:
            tree_hash = _tree_hash(self.project_id, self.dir)
        if not tree_hash or not self.has_content():
            warn("No docs directory in project repo at HEAD for builder %s" %
                 self.builder)
            return False, 'no_doc_dir_found'
        mc.set(LAST_TREE_HASH_MC_KEY % (self.project_id, self.builder),
               tree_hash)

        if os.path.exists(self.docs_dir):
            shutil.rmtree(self.docs_dir, ignore_errors=True)
        try:
            os.makedirs(self.docs_dir)
        except OSError:
            pass
        ret, msg = _export_docs_tree(self.project_id, tree_hash,
                                     self.temp_dir_root)
        if not ret:
            return False, msg
        if self.config['checkout_root']:
            self.temp_dir = os.path.join(self.temp_dir_root, self.dir)
        else:
            self.temp_dir = self.temp_dir_root
        return True, 'success'
Ejemplo n.º 7
0
 def _save_build_state(self, status, message=''):
     last_build = {
         'message': message,
         'date': dt.datetime.now(),
         'status': status,
         'builds': self.builds_logs,
     }
     mc.set(LAST_BUILD_MC_KEY % self.project_id, last_build)
Ejemplo n.º 8
0
 def _save_build_state(self, status, message=''):
     last_build = {
         'message': message,
         'date': dt.datetime.now(),
         'status': status,
         'builds': self.builds_logs,
     }
     mc.set(LAST_BUILD_MC_KEY % self.project_id, last_build)
Ejemplo n.º 9
0
 def award(self, item_id, reason=None, kind=KIND_USER):
     params = (item_id, self.id, reason, kind, datetime.now())
     store.execute(
         "insert into badge_item(item_id, badge_id, reason, kind, date) "
         "values(%s, %s, %s, %s, %s)", params)
     store.commit()
     mc_key = MC_NEW_BADGE % (item_id, kind)
     badges = mc.get(mc_key) or []
     badges.append(str(self.id))
     mc.set(mc_key, badges)
Ejemplo n.º 10
0
def get_unreleased_commit_num(project):
    last_release_info = get_release(project.repository)
    from_ref = last_release_info['last_rev'] if last_release_info else None
    key = MC_KEY_UNRELEASE_COMMITS % (project.id, project.default_sha,
                                      from_ref)
    num = mc.get(key)
    if num is None:
        commits = project.repo.get_commits(project.default_branch,
                                           from_ref=from_ref,
                                           max_count=100)
        num = len(commits)
        mc.set(key, num, ONE_DAY)
    return num
Ejemplo n.º 11
0
def get_unreleased_commit_num(project):
    last_release_info = get_release(project.repository)
    from_ref = last_release_info['last_rev'] if last_release_info else None
    key = MC_KEY_UNRELEASE_COMMITS % (project.id,
                                      project.default_sha,
                                      from_ref)
    num = mc.get(key)
    if num is None:
        commits = project.repo.get_commits(project.default_branch,
                                           from_ref=from_ref,
                                           max_count=100)
        num = len(commits)
        mc.set(key, num, ONE_DAY)
    return num
Ejemplo n.º 12
0
class SphinxDocs(object):  # TODO rename this is not sphinx-only
    builds_logs = []
    disabled_reason = 'Unknown reason'

    def __init__(self, project_name, allow_old_conf=True):
        project = CodeDoubanProject.get_by_name(project_name)
        assert project, "Need existing project"
        self.project_id = project.id
        # if not project or not is_git_dir(project.git_path):
        if not project:
            self.enabled = False
            self.disabled_reason = "No project +_+"
            return
        try:
            self.conf_new = project.conf.get('docs', None)
        except GytRepoNotInited:
            self.enabled = False
            self.disabled_reason = "No project +_+"
            return

        if self.conf_new:
            try:
                _check_conf(self.conf_new)
            except AssertionError, err:
                logging.warning("Docs config error: %s" % err)
                self.enabled = False
                self.disabled_reason = str(err)
                return
        self.enabled = True
        self.builders = _builders_list(project.id)
        mc.set(LAST_BUILD_MC_KEY % self.project_id, None)
Ejemplo n.º 13
0
 def _set(self, target_id, value):
     mc.set(self.mc_key(target_id), value)
Ejemplo n.º 14
0
 def __init__(self, apikey, user_id):
     self.code = uuid.uuid1().hex[:20]
     mc.set(self.__mc_key(apikey, self.code), user_id, TEN_MINUTES)
Ejemplo n.º 15
0
 def set(self, key, value, **kw):
     expiretime = kw.get("timeout", ONE_HOUR)
     mc.set(key, value, expiretime)
Ejemplo n.º 16
0
 def __init__(self, user_id):
     self.cid = uuid.uuid1().hex[:20]
     mc.set(OAUTH_CONFIRM % (user_id, self.cid), 1, ONE_MINUTE)
Ejemplo n.º 17
0
 def set(self, key, value, **kw):
     expiretime = kw.get('timeout', ONE_HOUR)
     mc.set(key, value, expiretime)
Ejemplo n.º 18
0
 def __init__(self, apikey, user_id):
     self.code = uuid.uuid1().hex[:20]
     mc.set(self.__mc_key(apikey, self.code), user_id, TEN_MINUTES)
Ejemplo n.º 19
0
 def __init__(self, user_id):
     self.cid = uuid.uuid1().hex[:20]
     mc.set(OAUTH_CONFIRM % (user_id, self.cid), 1, ONE_MINUTE)
Ejemplo n.º 20
0
 def clean_up(self):
     if self.temp_dir_root and os.path.isdir(self.temp_dir_root):
         shutil.rmtree(self.temp_dir_root)
     mc.set(LAST_TREE_HASH_MC_KEY, None)
     mc.set(LAST_BUILD_MC_KEY, None)
Ejemplo n.º 21
0
 def _set(self, target_id, value):
     mc.set(self.mc_key(target_id), value)
Ejemplo n.º 22
0
 def clean_up(self):
     if self.temp_dir_root and os.path.isdir(self.temp_dir_root):
         shutil.rmtree(self.temp_dir_root)
     mc.set(LAST_TREE_HASH_MC_KEY, None)
     mc.set(LAST_BUILD_MC_KEY, None)