-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
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
base: master
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 |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
| 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
Author
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. Function
|
||
|
|
||
| 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
Author
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. Function
|
||
|
|
||
|
|
||
| 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
Author
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. Function
|
||
|
|
||
|
|
||
| def expand_tree_node(node): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: | ||
|
Author
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. Function
|
||
| msg = "Command '%s' return non-zero exit status %d" % (cmd, res) | ||
| raise CalledProcessError(msg) | ||
| vars(subprocess).setdefault('check_call', _check_call_py24) | ||
|
|
@@ -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
Author
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. Function
|
||
| finally: | ||
| devnull.close() | ||
| return True | ||
|
|
@@ -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
Author
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. Function
|
||
| finally: | ||
| devnull.close() | ||
| return True | ||
|
|
@@ -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 | ||
|
Author
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. Function
|
||
| finally: | ||
| devnull.close() | ||
| return True | ||
|
|
||
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.
Function
flatten_treerefactored with the following changes:yield-from)