def generateJSONStr(name, summary, descr): json_str = INDENT*2+'{\n' json_str += INDENT*3 + JSONObj.createJSONStr(LANG_JSON_KET[0], name) json_str += INDENT*3 + JSONObj.createJSONStr(LANG_JSON_KET[1], summary) json_str += INDENT*3 + JSONObj.createJSONStr(LANG_JSON_KET[2], descr) return json_str[0:-2]+'\n'+INDENT*2+'},\n'
def convertToJSONStr(repo_name, propStr): config = ConfigParser() con = '[tag]\n'+propStr config.read_string(con) for item in config.sections(): jsonStr = INDENT*2+'{\n'+INDENT*3+JSONObj.createJSONStr('name',repo_name) for key in config.options(item): jsonStr += INDENT*3+JSONObj.createJSONStr(key, config.get(item, key)) return jsonStr[0:-2]+'\n'+INDENT*2+'},\n'
def convertToJSONStr(repo_name, propStr, lang_item): config = ConfigParser() con = '[tag]\n'+propStr config.read_string(con) for item in config.sections(): jsonStr = INDENT*2+'{\n'+INDENT*3+JSONObj.createJSONStr(LANG_JSON_KET[0],repo_name) for key in LANG_JSON_KET[1:]: if key.lower() in config.options(item): jsonStr += INDENT*3+JSONObj.createJSONStr(key, config.get(item, key)) else: raise Exception("FormatError: "+key+" is not a legal key in lang properties file of "+repo_name+"-"+lang_item+". Please check!") return jsonStr[0:-2]+'\n'+INDENT*2+'},\n'
def __init__(self, meta_file): self.key_list = [] meta_content = '' try: meta_content, self.key_list = self.parseMetaContent(meta_file) except IOError as e: print("Manifest file open error: " + str(e)) raise e except Exception as e: print("Manifest file format error: " + str(e)) raise e self.meta_list = [] for key in self.key_list: val = re.findall(key + "\s*:\s*(.+?)\n", meta_content, re.S) if len(val) == 0: continue self.meta_list.append(JSONObj(key, val[0]))
def __init__(self, repo_name): repo_info_json_url = re.sub('repos_name', repo_name, InfoJSONObj.RAW_INFO_JSON_URL) try: self.repo_info_json = json.loads( urllib.request.urlopen(repo_info_json_url).read().decode( 'utf-8')) except UnicodeDecodeError: raise Exception( "UnicodeDecodeError: " + repo_name + "'s info.json has non-unicode character. Please check!" + "\nSwitch to next repo.\n\n") except urllib.error.HTTPError: raise Exception( "HTTPError: " + repo_name + "'s info.json does not have info.json, but this may not be a problem. Please check!" + "\nSwitch to next repo.\n\n") except ValueError: raise Exception( "ValueError: " + repo_name + "'s info.json has an illegal format. Please check!" + "\nSwitch to next repo.\n\n") except Exception: raise Exception( "Exception: " + repo_name + "'s info.json has an unknown error. Please check!" + "\nSwitch to next repo.\n\n") self.item_list = [] for key in InfoJSONObj.KEY_LIST: try: if type(self.repo_info_json[key]) == list: val = self.repo_info_json[key][0] else: val = self.repo_info_json[key] self.item_list.append(JSONObj(key, val.strip())) except: raise ValueError( "info.json missed some of the items below:\n" "type, provider, software, language, category, promotion.")
def __init__(self): self.item_list = [] for page_index in range( 1, math.floor(GithubApiInfoObj.MAX_REPO_NUM / GithubApiInfoObj.PER_PAGE) + 1): try: pageName = GithubApiInfoObj.GITHUB_API_URL.format( page_index, GithubApiInfoObj.PER_PAGE) api_json_data = json.loads( urllib.request.urlopen(pageName).read().decode('utf-8')) except: raise Exception("Cannot request data from github api: '" + pageName + "'.\n") if len(api_json_data) == 0: break for item in api_json_data: temp_json_list = [] #ignore .io repository if ('IBMPredictiveAnalytics.github.io' == item['name']): continue for key in GithubApiInfoObj.KEY_LIST: if key == 'repository': key_name_in_api = 'name' else: key_name_in_api = key try: temp_json_list.append( JSONObj(key, item[key_name_in_api].strip())) except: raise Exception("Github api (" + GithubApiInfoObj.GITHUB_API_URL + ") does not provide information of " + key + ". Please check!\n") self.item_list.append(temp_json_list)
def getItemStr(LicenseItemObj): item_str = INDENT*2 + "{\n" item_str += INDENT*3 + JSONObj.createJSONStr(KEY_LIST[LICENSE_FILE_NAME], LicenseItemObj.getLicenseName()) item_str += INDENT*3 + "\"" + KEY_LIST[REPOS_NAME_LIST] + "\":"+ LicenseIndexItemStr.convertListToString(LicenseItemObj.getRepoNameList())\ + '\n' + INDENT*2 + '},\n' return item_str
def getItemStr(LicenseItemObj): item_str = INDENT*2 + "{\n" item_str += INDENT*3 + JSONObj.createJSONStr(KEY_LIST[LICENSE_FILE_NAME], LicenseItemObj.getLicenseName()) item_str += INDENT*3 + JSONObj.createJSONStr(KEY_LIST[REPOS_NAME_LIST], LicenseIndexItemStr.convertListToString(LicenseItemObj.getRepoNameList()))[1:-2]\ + '\n' + INDENT*2 + '},\n' return item_str