Skip to content
Open
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
26 changes: 10 additions & 16 deletions .update/do.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,25 @@ def flatten_tree(tree):
])
if 'contents' in tree:
for x in tree['contents']:
for y in flatten_tree(x):
yield y
yield from flatten_tree(x)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function flatten_tree refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)


def first_leaf(tree):
"""Find the first leaf node (Page) in the tree."""
if 'contents' in tree:
x = tree['contents'][0]
return first_leaf(x)
else:
if 'contents' not in tree:
return tree
x = tree['contents'][0]
return first_leaf(x)
Comment on lines -42 to +44
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function first_leaf refactored with the following changes:


def rex_uri(book, page):
if page is None:
uri = f'/books/{book}'
else:
uri = f'/books/{book}/pages/{page}'
return uri
return f'/books/{book}' if page is None else f'/books/{book}/pages/{page}'
Comment on lines -49 to +47
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rex_uri refactored with the following changes:



def cnx_uri_regex(book, page):
if page is None:
uri_regex = f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$"
else:
uri_regex = f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?:({page['id']}|{page['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$"
return uri_regex
return (
f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$"
if page is None
else f"/contents/({book['id']}|{book['short_id']})(@[.\d]+)?:({page['id']}|{page['short_id']})(@[.\d]+)?(/[-%\w\d]+)?$"
)
Comment on lines -57 to +55
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function cnx_uri_regex refactored with the following changes:



def expand_tree_node(node):
Expand Down
23 changes: 10 additions & 13 deletions files/homes/administrator/ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _check_call_py24(cmd, *args, **kwargs):
res = subprocess.call(cmd, *args, **kwargs)
class CalledProcessError(Exception):
pass
if not res == 0:
if res != 0:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _check_call_py24 refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

msg = "Command '%s' return non-zero exit status %d" % (cmd, res)
raise CalledProcessError(msg)
vars(subprocess).setdefault('check_call', _check_call_py24)
Expand Down Expand Up @@ -183,10 +183,9 @@ def has_powershell():
cmd = ['powershell', '-Command', 'echo test']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
Comment on lines -186 to +188
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function has_powershell refactored with the following changes:

finally:
devnull.close()
return True
Expand All @@ -201,10 +200,9 @@ def has_curl():
cmd = ['curl', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
Comment on lines -204 to +205
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function has_curl refactored with the following changes:

finally:
devnull.close()
return True
Expand All @@ -219,10 +217,9 @@ def has_wget():
cmd = ['wget', '--version']
devnull = open(os.path.devnull, 'wb')
try:
try:
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
except:
return False
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function has_wget refactored with the following changes:

finally:
devnull.close()
return True
Expand Down