Skip to content

Commit

Permalink
Review and pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mambelli committed Jan 24, 2025
1 parent cbe36e4 commit dd6d007
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ repos:
rev: v3.1.0
hooks:
- id: prettier
# HTML pre section bug https://github.com/prettier/prettier/issues/17042
exclude: "doc/factory/troubleshooting.html"
exclude_types:
- "python"
additional_dependencies:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

build/ReleaseManager/tags_example.yaml
creation/web_base/factoryEntryStatusNow.html
doc/factory/troubleshooting.html
5 changes: 4 additions & 1 deletion doc/factory/troubleshooting.html
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ <h2>
</h2>
The gfdiff tool has been improved to use positional arguments instead of options. You can use it to check differences among entries in the XML configuration. For example:
<blockquote>
<!-- prettier-ignore -->
<!-- prettier-ignore-start -->
<pre>
[0618] gfactory@gfactory-2 ~/mmascher/gfdiff$ ./gfdiff 10-hosted-ces.auto.xml.new 10-hosted-ces.auto.xml.bak241121 OSG_US_CHTC-Spark-CE1-gpu
--- text_a
Expand Down Expand Up @@ -825,9 +827,10 @@ <h2>
<files>
</files>
</pre>
<!-- prettier-ignore-end -->
</blockquote>
</div>

<div class="footer">
Banner image by
<a href="http://www.flickr.com/people/leafwarbler/">Madhusudan Katti</a>
Expand Down
62 changes: 19 additions & 43 deletions factory/tools/gfdiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,28 @@ def parse_opts():
"""Parse the command line options for this command"""
description = "Do a diff of two entries\n\n"

parser = argparse.ArgumentParser(description=description,
formatter_class=argparse.RawTextHelpFormatter)
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawTextHelpFormatter)

# Positional arguments
parser.add_argument(
"conf_a",
type=str,
help="Configuration for the first entry",
default="/etc/gwms-factory/glideinWMS.xml"
"conf_a", type=str, help="Configuration for the first entry.", default="/etc/gwms-factory/glideinWMS.xml"
)

parser.add_argument(
"conf_b",
type=str,
help="Configuration for the second entry",
default="/etc/gwms-factory/glideinWMS.xml"
"conf_b", type=str, help="Configuration for the second entry.", default="/etc/gwms-factory/glideinWMS.xml"
)

parser.add_argument(
"entry_a",
type=str,
help="Name of the first entry"
)
parser.add_argument("entry_a", type=str, help="Name of the first entry.")

parser.add_argument(
"entry_b",
type=str,
nargs="?", # Makes this positional argument optional
help="Name of the second entry (optional)"
help="Name of the second entry (optional). Defaults to the first entry name.",
)

# Named argument
parser.add_argument(
"--mergely",
action="count",
help="Only print the mergely link"
)
parser.add_argument("--mergely", action="count", help="Only print the mergely link")

options = parser.parse_args()

Expand All @@ -83,11 +68,7 @@ def handle_diff(text_a, text_b):
lines_b = text_b.splitlines()

# Create a unified diff
diff = difflib.unified_diff(
lines_a, lines_b,
fromfile="text_a", tofile="text_b",
lineterm=""
)
diff = difflib.unified_diff(lines_a, lines_b, fromfile="text_a", tofile="text_b", lineterm="")

# Print the diff line by line
for line in diff:
Expand All @@ -99,24 +80,20 @@ def handle_mergely(text_a, text_b):

url = "https://mergely.com/ajax/handle_save.php"

payload = {
"config": {},
"lhs_title": "",
"lhs": text_a,
"rhs_title": "",
"rhs": text_b
payload = {"config": {}, "lhs_title": "", "lhs": text_a, "rhs_title": "", "rhs": text_b}

# HTTP header field names are case-insensitive but MUST be converted to lowercase by the API
headers = {
"Accept": "*/*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Referer": "https://editor.mergely.com/",
"Content-Type": "application/json; charset=utf-8",
"Content-Length": str(len(str(payload))),
"Origin": "https://editor.mergely.com",
"Connection": "keep-alive",
}

headers = {}
headers["Accept"] = "*/*"
headers["Accept-Language"] = "en-US,en;q=0.5"
headers["Accept-Encoding"] = "gzip, deflate, br, zstd"
headers["Referer"] = "https://editor.mergely.com/"
headers["content-type"] = "application/json; charset=utf-8"
headers["Content-Length"] = str(len(str(payload)))
headers["Origin"] = "https://editor.mergely.com"
headers["Connection"] = "keep-alive"

res = requests.post(url, headers=headers, json=payload)

print("http://www.mergely.com/" + res.headers["location"])
Expand All @@ -143,7 +120,6 @@ def main():
print(f"Cannot find entry {options.entry_b} in the configuration file {options.conf_b}")
sys.exit(1)


text_a = get_entry_text(options.entry_a, options.conf_a)
text_b = get_entry_text(options.entry_b, options.conf_b)
handle_diff(text_a, text_b)
Expand Down

0 comments on commit dd6d007

Please sign in to comment.