def test_initFromNDJSON(self): ghp = libLF.GitHubProject() ghp.initFromRaw(self.owner, self.name, self.registry, self.modules, self.nStars, self.tarballPath) ndjson = ghp.toNDJSON() ghp2 = libLF.GitHubProject().initFromJSON(ndjson) ndjson2 = ghp2.toNDJSON() self.assertEqual(ndjson, ndjson2)
def test_toNDJSON(self): ghp = libLF.GitHubProject() ghp.initFromRaw(self.owner, self.name, self.registry, self.modules, self.nStars, self.tarballPath) ndjson = ghp.toNDJSON() self.assertTrue(re.search(r'owner', ndjson)) self.assertTrue(re.search(self.registry, ndjson))
def main(moduleInfoFile, outFile): nAttempts = 0 nSuccesses = 0 nFailures = 0 with open(moduleInfoFile, 'r') as inStream, \ open(outFile, 'w') as outStream: for line in inStream: try: line = line.strip() if len(line) > 0: nAttempts += 1 mi = libLF.ModuleInfo().initFromJSON(line) ghp = libLF.GitHubProject().initFromRaw( owner='UNKNOWN', name='UNKNOWN', registry=mi.registry, modules=[mi.toNDJSON()], tarballPath=mi.tarballPath) outStream.write(ghp.toNDJSON() + '\n') nSuccesses += 1 except: libLF.log('Discarding: {}'.format(line)) nFailures += 1 libLF.log( 'Out of {} ModuleInfo\'s: {} successful conversions, {} failures'. format(nAttempts, nSuccesses, nFailures))
def toGitHubProject(self): return libLF.GitHubProject() \ .initFromRaw(self.getOwner(), self.getName(), "maven", ["UNKNOWN"], nStars=self.nStars)
def test_initFromRaw(self): ghp = libLF.GitHubProject() ghp.initFromRaw(self.owner, self.name, self.registry, self.modules, self.nStars, self.tarballPath) self.assertEqual(self.owner, ghp.owner) self.assertEqual(self.name, ghp.name) self.assertEqual(self.registry, ghp.registry) self.assertEqual(self.modules, ghp.modules) self.assertEqual(self.nStars, ghp.nStars) self.assertEqual(self.tarballPath, ghp.tarballPath)
def loadGHPFile(ghpFile): """Returns libLF.GitHubProject[]""" ghps = [] libLF.log('Loading GHPs from {}'.format(ghpFile)) with open(ghpFile, 'r') as inStream: for line in inStream: line = line.strip() if len(line) == 0: continue try: # Build the GHP ghp = libLF.GitHubProject() ghp.initFromJSON(line) ghps.append(ghp) except KeyboardInterrupt: raise except BaseException as err: libLF.log('Exception parsing line:\n {}\n {}'.format(line, err)) return ghps
def getGHPs(projectFile): ghps = [] with open(projectFile, 'r') as inStream: for line in inStream: line = line.strip() if len(line) == 0: continue try: # Build a GitHubProject ghp = libLF.GitHubProject().initFromJSON(line) ghps.append(ghp) except KeyboardInterrupt: raise except BaseException as err: libLF.log('Exception parsing line:\n {}\n {}'.format( line, err)) libLF.log('Loaded {} ghps'.format(len(ghps))) return ghps
def test_getNModules(self): ghp = libLF.GitHubProject() ghp.initFromRaw(self.owner, self.name, self.registry, self.modules, self.nStars, self.tarballPath) self.assertEqual(len(ghp.modules), len(self.modules))