-
Notifications
You must be signed in to change notification settings - Fork 60
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
Update generateXml.py #559
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
Django==3.2.25 | ||
jpype1==1.3.0 | ||
numpy==1.22.4 | ||
djangorestframework==3.12.2 | ||
Django>=4.2,<4.3 | ||
jpype1==1.4.0 | ||
numpy>=1.25.0 | ||
djangorestframework>=3.14.0 | ||
bs4==0.0.1 | ||
requests==2.32.3 | ||
lxml==4.9.4 | ||
webdriver-manager==3.4.2 | ||
social-auth-core==4.1.0 | ||
social-auth-app-django==4.0.0 | ||
python-dotenv==0.17.1 | ||
lxml>=5.3.0 | ||
webdriver-manager>=3.8.6 | ||
social-auth-core>=4.3,<5.0 | ||
social-auth-app-django>=5.0,<6.0 | ||
python-dotenv>=1.0.0 | ||
gevent==23.9.1 | ||
gunicorn==22.0.0 | ||
gunicorn==23.0.0 | ||
#for testing | ||
selenium==3.14.1 | ||
django-oauth-toolkit==1.5.0 | ||
django-rest-framework-social-oauth2==1.1.0 | ||
selenium>=4.10.0 | ||
django-oauth-toolkit>=2.0.0 | ||
django-rest-framework-social-oauth2>=1.1.0 | ||
spdx-tools==0.8.3 | ||
ntia-conformance-checker==3.0.2 | ||
ntia-conformance-checker==3.1.0 | ||
-e git+https://github.com/spdx/[email protected]#egg=spdx-license-matcher |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import math | ||
import re | ||
import xml.etree.ElementTree as ET | ||
from xml.dom import minidom | ||
from itertools import chain, tee | ||
|
||
entityMap = { | ||
|
@@ -23,7 +23,7 @@ def previous_and_current(some_iterable): | |
|
||
def escapeXmlData(string): | ||
for initial,final in list(entityMap.items()): | ||
string.replace(initial, final) | ||
string = string.replace(initial, final) # assign changed string back | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
return string | ||
|
||
|
||
|
@@ -45,8 +45,9 @@ def wrapBullets(string, item): | |
numberBullet = re.search(numberBullets, string) | ||
symbolBullet = re.search(symbolBullets, string) | ||
bullet = letterBullet or numberBullet or symbolBullet | ||
ET.SubElement(item, "bullet").text = bullet.group(2) | ||
string = string.replace(bullet.group(2), '').strip() | ||
if bullet: # Bullet must exist | ||
ET.SubElement(item, "bullet").text = bullet.group(2) | ||
string = string.replace(bullet.group(2), '').strip() | ||
return string | ||
|
||
|
||
|
@@ -61,7 +62,7 @@ def groupLines(lines): | |
if not matches: | ||
depth = 0 | ||
else: | ||
depth = int(math.floor(len(matches)/4)) | ||
depth = len(matches) // 4 # no need to use math.floor() | ||
tagType = 'item' | ||
lis.append({'data':line, 'depth':depth, 'tagType':tagType}) | ||
else: | ||
|
@@ -154,4 +155,16 @@ def generateLicenseXml(licenseOsi, licenseIdentifier, licenseName, listVersionAd | |
textElement = getTextElement(points) | ||
license.append(textElement) | ||
xmlString = ET.tostring(root, method='xml', encoding='unicode') | ||
|
||
# Format the XML string with indentation for better readability | ||
xmlString = minidom.parseString(xmlString).toprettyxml(indent=" ") | ||
|
||
# Remove extra blank lines added by `toprettyxml()`, ensuring clean output | ||
clean_lines = [] | ||
for line in xmlString.splitlines(): | ||
if line.strip(): # Only keep non-empty lines | ||
clean_lines.append(line) | ||
|
||
xmlString = "\n".join(clean_lines) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this code block do? Can you provide an example? |
||
|
||
return xmlString |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.support import expected_conditions as EC | ||
from selenium.webdriver.firefox.options import Options | ||
from selenium.webdriver.firefox.service import Service | ||
from webdriver_manager.firefox import GeckoDriverManager | ||
import time | ||
import datetime | ||
|
@@ -648,7 +649,8 @@ class LicenseXMLEditorTestCase(StaticLiveServerTestCase): | |
def setUp(self): | ||
options = Options() | ||
options.add_argument('-headless') | ||
self.selenium = webdriver.Firefox(executable_path=GeckoDriverManager().install(), firefox_options=options) | ||
service = Service(GeckoDriverManager().install()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's define this globally, instead of defining for each setUp |
||
self.selenium = webdriver.Firefox(service=service, options=options) | ||
self.initialXML = '<?xml version="1.0" encoding="UTF-8"?><SPDXLicenseCollection xmlns="http://www.spdx.org/license"><license></license></SPDXLicenseCollection>' | ||
self.invalidXML = '<?xml version="1.0" encoding="UTF-8"?><SPDXLicenseCollection xmlns="http://www.spdx.org/license"><license></license>' | ||
super(LicenseXMLEditorTestCase, self).setUp() | ||
|
@@ -1080,7 +1082,8 @@ class ArchiveLicenseRequestsViewsTestCase(StaticLiveServerTestCase): | |
def setUp(self): | ||
options = Options() | ||
options.add_argument('-headless') | ||
self.selenium = webdriver.Firefox(executable_path=GeckoDriverManager().install(), firefox_options=options) | ||
service = Service(GeckoDriverManager().install()) | ||
self.selenium = webdriver.Firefox(service=service, options=options) | ||
super(ArchiveLicenseRequestsViewsTestCase, self).setUp() | ||
|
||
def tearDown(self): | ||
|
@@ -1273,7 +1276,8 @@ class PromoteLicenseNamespaceViewsTestCase(StaticLiveServerTestCase): | |
def setUp(self): | ||
options = Options() | ||
options.add_argument('-headless') | ||
self.selenium = webdriver.Firefox(executable_path=GeckoDriverManager().install(), firefox_options=options) | ||
service = Service(GeckoDriverManager().install()) | ||
self.selenium = webdriver.Firefox(service=service, options=options) | ||
#login | ||
TEST_LOGIN_INFO = { | ||
"provider": "github", | ||
|
@@ -1349,7 +1353,8 @@ class ArchiveLicenseNamespaceViewsTestCase(StaticLiveServerTestCase): | |
def setUp(self): | ||
options = Options() | ||
options.add_argument('-headless') | ||
self.selenium = webdriver.Firefox(executable_path=GeckoDriverManager().install(), firefox_options=options) | ||
service = Service(GeckoDriverManager().install()) | ||
self.selenium = webdriver.Firefox(service=service, options=options) | ||
super(ArchiveLicenseNamespaceViewsTestCase, self).setUp() | ||
|
||
def tearDown(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a util func for this and use that.
Also, make sure this works instead of
request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'