Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to retrieve upload stats #28

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions fossdriver/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,32 @@ def parseSingleJobData(content):
job.status == "Completed"):
job.reportId = int(jobReportIdString)
return job

def parseStatisticsFromLicenseBrowser(content):
# parsing the full HTML page content
soup = bs4.BeautifulSoup(content, "lxml")
# looking for the table with id licsummary
elt = soup.find(id='licsummary')
tds = elt.find_all("td")
# check that they match expected labels, if so then capture values
if len(tds) < 16:
return []
if (tds[0].contents[0] != "Unique licenses" or
tds[3].contents[0] != "Files" or
tds[4].contents[0] != "Unique scanner detected licenses" or
tds[7].contents[0] != "Unique concluded licenses" or
tds[8].contents[0] != "Licenses found" or
tds[11].contents[0] != "Licenses concluded" or
tds[12].contents[0] != "Files with no detected licenses" or
tds[15].contents[0] != "Concluded files with no detected licenses"):
return []
return [
("Unique licenses", int(tds[1].contents[0])),
("Files", int(tds[2].contents[0])),
("Unique scanner detected licenses", int(tds[5].contents[0])),
("Unique concluded licenses", int(tds[6].contents[0])),
("Licenses found", int(tds[9].contents[0])),
("Licenses concluded", int(tds[10].contents[0])),
("Files with no detected licenses", int(tds[13].contents[0])),
("Concluded files with no detected licenses", int(tds[14].contents[0])),
]
15 changes: 15 additions & 0 deletions fossdriver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,21 @@ def GetLicenses(self, uploadNum, itemNum):
licenses = fossdriver.parser.parseAllLicenseData(results.content)
return licenses

def GetUploadStatistics(self, uploadNum, itemNum):
"""
Obtain a list of tuples in (str, int) format, where each str is one
of the "Summary" values from the left side of the License view, and
the int is the corresponding count.
Requires upload and item numbers due to Fossology server interface.
Arguments:
- uploadNum: valid ID number for an existing upload.
- topTreeItemNum: valid ID number for an item in that upload.
"""
endpoint = "/repo/?mod=license&upload={}&item={}".format(uploadNum, itemNum)
results = self._get(endpoint)
stats = fossdriver.parser.parseStatisticsFromLicenseBrowser(results.content)
return stats

def FindLicenseInParsedList(self, parsedLicenses, licName):
"""
Find the ParsedLicense object with the given license name.
Expand Down