Skip to content

Commit

Permalink
licenses changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeloca committed Oct 11, 2017
1 parent aea4bc0 commit 6e9eed9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ecosystemDataManager/ecosystemDataManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ def groupsEvolution(self):
history = package.getHistory()
for i in range(len(history) - 1):
versionFrom = history[i]
versionTo = history[i + 1]
if not versionFrom.getDatetime():
continue
versionTo = history[i + 1]
if not versionTo.getDatetime():
continue
licensesFrom = versionFrom.getLicenses()
licensesTo = versionTo.getLicenses()
if not licensesFrom:
Expand Down
68 changes: 68 additions & 0 deletions generateCSVLicensesChanges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from ecosystemDataManager.ecosystemDataManager import EcosystemDataManager
from ecosystemDataManager.group import Group
import csv
import sys

if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage:", sys.argv[0], "<ecosystem> [<file>]")
sys.exit(1)
if len(sys.argv) > 2:
file = sys.argv[2]
else:
print("file not provided. using default.")
file = "licensesChanges.csv"
try:
open(file)
print("file loaded")
file = open(file, "a")
file = csv.writer(file, delimiter = ';')
except Exception as e:
file = open(file, "w")
file = csv.writer(file, delimiter = ';')
file.writerow(["ecosystem","package","versions","unknownTOknown", "knownTOunknown", "latestGroup"])
print("file not loaded. initialized.")
ecosystem = sys.argv[1]
ecosystemDataManager = EcosystemDataManager(ecosystem)
for package in ecosystemDataManager.getPackages():
unknownTOknown = 0
knownTOunknown = 0
history = package.getHistory()
for i in range(len(history) - 1):
versionFrom = history[i]
versionTo = history[i + 1]
if not versionFrom.getDatetime():
continue
if not versionTo.getDatetime():
continue
licensesFrom = versionFrom.getLicenses()
licensesTo = versionTo.getLicenses()
if not licensesFrom:
if licensesTo:
for licenseTo in licensesTo:
groupTo = licenseTo.getGroup()
if groupTo == Group.KNOWN:
unknownTOknown += 1
elif not licensesTo:
for licenseFrom in licensesFrom:
groupFrom = licenseFrom.getGroup()
if groupFrom == Group.KNOWN:
knownTOunknown += 1
else:
for licenseFrom in licensesFrom:
for licenseTo in licensesTo:
groupFrom = licenseFrom.getGroup()
groupTo = licenseTo.getGroup()
if groupFrom == Group.KNOWN:
if groupTo == Group.NONE or groupTo == Group.UNDEFINED or groupTo == Group.UNKNOWN:
knownTOunknown += 1
if groupFrom == Group.NONE or groupFrom == Group.UNDEFINED or groupFrom == Group.UNKNOWN:
if groupTo == Group.KNOWN:
unknownTOknown += 1
try:
if unknownTOknown > 0 or knownTOunknown > 0:
versions = len(package)
latestGroup = ",".join([license.getGroup().name for license in package.getLatestVersion().getLicenses()])
file.writerow([ecosystem, package, versions, unknownTOknown, knownTOunknown, latestGroup])
except Exception as e:
print(package, len(package), "discarted")
12 changes: 12 additions & 0 deletions generateCSVUnknown.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@
if license.getGroup() == Group.NONE or license.getGroup() == Group.UNKNOWN or license.getGroup() == Group.UNDEFINED:
group = license.getGroup().name
author = version.getAuthor()
if author:
author = author.replace("\"", "").replace("'", "").replace(";", "")
author = "\"" + author + "\""
email = version.getEmail()
if email:
email = email.replace("\"", "").replace("'", "").replace(";", "")
email = "\"" + email + "\""
repository = package.getRepository()
if repository:
repository = repository.replace("\"", "").replace("'", "").replace(";", "")
repository = "\"" + repository + "\""
licenses = ", ".join(version.getOriginalLicenses())
if licenses:
licenses = licenses.replace("\"", "").replace("'", "").replace(";", "")
licenses = "\"" + licenses + "\""
normalized = ", ".join([str(license) for license in version.getLicenses()])
parents = version.getContextSize()
file.writerow([ecosystem, package, version, group, author, email, repository, licenses, normalized, parents])
Expand Down

0 comments on commit 6e9eed9

Please sign in to comment.