Skip to content

Commit

Permalink
merged documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeloca committed Dec 9, 2017
2 parents a4ba110 + ce0f711 commit 34a9d34
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 16 deletions.
31 changes: 26 additions & 5 deletions ecosystemDataManager/license.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
from .group import Group

class License(object):
"""docstring for License"""
"""
This class is responsible for managing all attributes of lincese class,
like it self ecosystemDataManager, version and index
"""
def __init__(self, ecosystemDataManager, version, index):
super(License, self).__init__()
self.ecosystemDataManager = ecosystemDataManager
self.version = version
self.index = index
"""
This function is internally called for initialization of the class and set all attributes
"""

def getName(self):
versionsHasLicenses = self.ecosystemDataManager.get("VersionsHasLicenses")
return versionsHasLicenses[self.version.getIndex()][self.index]
"""
This function is internally called to return the license name itself
"""

def getGroup(self):
licensesHasGroup = self.ecosystemDataManager.get("LicensesHasGroup")
return Group(licensesHasGroup[self.version.getIndex()][self.index])
"""
This function is internally called to return the license group itself
"""

def setGroup(self, group):
licensesHasGroup = self.ecosystemDataManager.get("LicensesHasGroup")
licensesHasGroup[self.version.getIndex()][self.index] = group.value
return self

"""
This function is internally called to set the new group
"""
def __hash__(self):
return self.index

"""
This overwritten function is internally called to return the self index for hash
"""
def __eq__(self, other):
if type(other) == str:
return self.getName() == other
elif type(other) != type(self):
return False
return self.getName() == other.getName()

"""
This overwritten function is internally called to compare this license with other license by license Name
"""
def __str__(self):
return self.getName()
return self.getName()
"""
This overwritten function is internally called to return license Name
"""
19 changes: 18 additions & 1 deletion ecosystemDataManager/occurrence.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from .dependency import Dependency

class Occurrence(object):
"""docstring for Occurrence"""
"""
This class is responsible for represent an edge of a graph, and that edge is the
occurrence of a dependency
Constructor is internally called for initialization of the class and set all attributes.
If haven't set all requested this class cound't be initialized.
"""
def __init__(self, ecosystemDataManager, outVersion, inVersion):
super(Occurrence, self).__init__()
if not ecosystemDataManager or not outVersion or not inVersion:
Expand All @@ -10,14 +15,26 @@ def __init__(self, ecosystemDataManager, outVersion, inVersion):
self.outVersion = outVersion
self.inVersion = inVersion

"""
This function is internally called to return the vertex that the edge has its origin
"""
def getOutVersion(self):
return self.outVersion

"""
This function is internally called to return the vertex that this vertex points
"""
def getInVersion(self):
return self.inVersion

"""
This function is internally called to return the inverse of this ocurrence. That is, a dependency edge.
"""
def getDependency(self):
return Dependency(self.ecosystemDataManager, self.inVersion, self.outVersion, None)

"""
This overwritten function is internally called to return license Name
"""
def __str__(self):
return self.outVersion.__str__() + " --> " + self.inVersion.__str__()
72 changes: 68 additions & 4 deletions ecosystemDataManager/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,95 @@
from .version import Version

class Package(object):
"""docstring for Package"""
"""
This function is internally called for initialization of the class and set all attributes.
If haven't set all requested this class cound't be initialized.
"""
def __init__(self, ecosystemDataManager, index):
super(Package, self).__init__()
if not ecosystemDataManager or index == None:
raise Exception
self.ecosystemDataManager = ecosystemDataManager
self.index = index

"""
This function is internally called to return the index itself
"""
def getIndex(self):
return self.index

"""
This function is internally called to return the ecosystem data manager itself
"""
def getEcosystemDataManager(self):
return self.ecosystemDataManager

"""
This function is internally called to set table value by the requests attributes
"""
def set(self, attribute, value):
table = self.ecosystemDataManager.get(attribute)
table[self.index] = value
return self

"""
This function is internally called to return the requested attribute of this package
"""
def get(self, attribute):
table = self.ecosystemDataManager.get(attribute)
return table[self.index]

"""
This function is internally called to return the package name itself
"""
def getName(self):
return self.get("PackagesHasIndex")

"""
This function is internally called to return the repository itself
"""
def setRepository(self, repository):
self.set("PackagesHasRepository", repository)
return self

"""
This function is internally called to return the repository itself
"""
def getRepository(self):
return self.get("PackagesHasRepository")

"""
This function is internally called to set some tags
"""
def setTags(self, tags):
self.set("PackagesHasTags", tags)
return self

"""
This function is internally called to return the tags itself
"""
def getTags(self):
return self.get("PackagesHasTags")

"""
This function is internally called to return version by requested index
"""
def getVersionByIndex(self, index):
if index < 0:
raise Exception
try:
return Version(self.ecosystemDataManager, self, index)
except Exception as e:
raise e

def resolve(self, strVersion):
versions = self.getVersions()
for version in versions:
if version.satisfies(strVersion):
return version
raise Exception

"""
This function is internally called to add a new version to this package.
"""
def addVersion(self, name):
packagesHasVersions = self.ecosystemDataManager.get("PackagesHasVersions")
try:
Expand Down Expand Up @@ -84,7 +118,7 @@ def addVersion(self, name):
self.ecosystemDataManager.get("DependenciesHasRequirements").append([])
finally:
return self.getVersion(name)

def getVersion(self, name):
versionsHasIndex = self.get("PackagesHasVersions")
try:
Expand Down Expand Up @@ -256,42 +290,72 @@ def evaluate(self, dependency):
inLicenses = dependency.getLicenses()
return self.ecosystemDataManager.evaluateInLicenses(inLicenses)

"""
This function is internally called to return if at least one version is irregular, this
package is irregular too.
"""
def isIrregular(self):
for version in self.getVersions():
if version.isIrregular():
return True
return False

"""
This function is internally called to return if any version is irregular, this
package is regular.
"""
def isRegular(self):
for version in self.getVersions():
if version.isIrregular():
return False
return True

"""
This function is internally called to return a list of iregular versions
"""
def getIrregularVersions(self):
return [version for version in self.getVersions() if version.isIrregular()]

"""
This function is internally called to return a list of regular versions
"""
def getRegularVersions(self):
versions = self.getVersions()
irregularVersions = self.getIrregularVersions()
return list(set(versions) - set(irregularVersions))

"""
This function is internally called to return if itself pakcage is affected ou not, by
the global regularity rate.
"""
def isAffected(self):
for version in self.getVersions():
if version.getGlobalRegularityRate() < 1:
return True
return False

"""
This overwritten function is internally called to return the self index for hash
"""
def __hash__(self):
return self.index

"""
This overwritten function is internally called to return the self len by len of PackagesHasVersions
"""
def __len__(self):
return len(self.get("PackagesHasVersions"))

"""
This overwritten function is internally called to compare this license with other license by license Index
"""
def __eq__(self, other):
if type(other) != type(self):
return False
return other.getIndex() == self.getIndex()

"""
This overwritten function is internally called to return license Name
"""
def __str__(self):
return self.getName()
22 changes: 17 additions & 5 deletions ecosystemDataManager/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def __init__(self, ecosystemDataManager, package, index):
package = self.ecosystemDataManager.getPackageByIndex(versionsHasPackage[index])
self.package = package
self.index = index

"""
This function is internally called for initialization of the class and set all attributes.
If haven't set ecosystemDataManager or index requested this class cound't be initialized.
"""
def getIndex(self):
return self.index

Expand All @@ -32,7 +35,9 @@ def get(self, attribute):

def getName(self):
return self.get("VersionsHasIndex")

"""
This function is internally called to return the version name itself
"""
def setDatetime(self, datetime):
self.set("VersionsHasDatetime", datetime)
return self
Expand Down Expand Up @@ -321,11 +326,18 @@ def calculateGlobalRegularityMean(self, start = True):

def __hash__(self):
return self.index

"""
This overwritten function is internally called to return the self index for hash
"""
def __eq__(self, other):
if type(other) != type(self):
return False
return other.getIndex() == self.getIndex()

"""
This overwritten function is internally called to compare this license with other license by license Index
"""
def __str__(self):
return self.getPackage().getName() + "@" + str(self.getName())
return self.getPackage().getName() + "@" + str(self.getName())
"""
This overwritten function is internally called to return license Name
"""
9 changes: 9 additions & 0 deletions fetchDependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def getContent(url):
def getJson(url):
return json.loads(getContent(url))

"""
Get all packages from NPM ecosystem
"""
def fetchNpm(package):
if package in VISITED_PACKAGES:
return
Expand Down Expand Up @@ -99,6 +102,9 @@ def fetchNpm(package):
except Exception as e:
print(package.getName() + "@" + metadataVersion, "no dependencies", e)

"""
Get all packages from Rubygems ecosystem
"""
def fetchRubygemsPackages():
registry = 'https://rubygems.org/'
packages = getContent(os.path.join(registry, 'versions'))
Expand Down Expand Up @@ -169,6 +175,9 @@ def fetchRubygems(package):
except Exception as e:
print(package.getName() + "@" + metadataVersion, "VERSION FETCH FAIL")

"""
Get all packages from Cran ecosystem
"""
def fetchCran(package):
ecosystemDataManager = package.getEcosystemDataManager()
registry = "https://cran.r-project.org/web/packages/"
Expand Down
3 changes: 3 additions & 0 deletions generateCSVLicensesChanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import csv
import sys

"""
Generate a list of licenses changes to CSV formats
"""
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<ecosystem> [<file>]")
Expand Down
3 changes: 3 additions & 0 deletions generateCSVUnknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import csv
import sys

"""
Generate a list of licenses unknown to CSV formats
"""
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<ecosystem> [<file>]")
Expand Down
Loading

0 comments on commit 34a9d34

Please sign in to comment.