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'
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 {}
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
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
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'
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)
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)
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
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)
def _set(self, target_id, value): mc.set(self.mc_key(target_id), value)
def __init__(self, apikey, user_id): self.code = uuid.uuid1().hex[:20] mc.set(self.__mc_key(apikey, self.code), user_id, TEN_MINUTES)
def set(self, key, value, **kw): expiretime = kw.get("timeout", ONE_HOUR) mc.set(key, value, expiretime)
def __init__(self, user_id): self.cid = uuid.uuid1().hex[:20] mc.set(OAUTH_CONFIRM % (user_id, self.cid), 1, ONE_MINUTE)
def set(self, key, value, **kw): expiretime = kw.get('timeout', ONE_HOUR) mc.set(key, value, expiretime)
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)