def github_AddFileFromGitHub(req, user): gh_user = '******' gh_repo = 'melya' prefix = 'onlinesrc/' # quite inefficient, but who cares rr = getHeadMasterTree(gh_user, gh_repo, True) if not rr: return RetType.JSONFAIL file_sha_map = dict((x.get('path').split('/',1)[1], x.get('sha')) for x in rr.get('tree') if x.get('path').startswith(prefix) and x.get('type') == 'blob') fn = req.get('filename') if not fn: return RetType.JSONFAIL, {'text':'no file specified'} if fn not in file_sha_map: return RetType.JSONFAIL, {'text':'File not found on github'} sha = file_sha_map[fn] content = getBlobContent(gh_user, gh_repo, sha) if content is None: return RetType.JSONFAIL, {'text':'Failed to get file content from github'} ok, res = internalAddFile(fn, content, user.key()) if ok: return RetType.JSONSUCCESS, res return RetType.JSONFAIL, res
def github_PopulateMissingFiles(req, user): gh_user = '******' gh_repo = 'melya' prefix = 'onlinesrc/' add_if_missing = True # maybe make this optional? rr = getHeadMasterTree(gh_user, gh_repo, True) if not rr: return RetType.JSONFAIL aa = [ (x.get('path').split('/',1)[1], x.get('sha')) for x in rr.get('tree') if x.get('path').startswith(prefix) and x.get('type') == 'blob'] res = [] for path,sha in aa: fv = datamodel.DB_FileVersion.getMostRecent(path, 'z', keys_only=True) if not fv: if add_if_missing: content = getBlobContent(gh_user, gh_repo, sha) if content: ok, resobj = internalAddFile(path, content, user.key()) if ok: res.append('Added file: %s (%s)<br/>\n' % (path, sha)) else: res.append('Added file failed: %s (%s)<br/>\n' % (path, sha)) else: res.append('Failed to get content for: %s (%s)<br/>\n' % (path, sha)) else: res.append('GitHub file not found locally: %s (%s)<br/>\n' % (path, sha)) else: found_sha = fv.parent().name() if sha == found_sha: res.append('GitHub file found with same sha: %s (%s)<br/>\n' % (path, sha)) else: res.append('GitHub file found with different sha: %s (github: %s - local: %s)<br/>\n' % (path, sha, found_sha)) return RetType.RAW, ''.join(sorted(res))