-
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 |
|---|---|---|
|
|
@@ -7,9 +7,7 @@ | |
| from .win32 import windll | ||
|
|
||
|
|
||
| winterm = None | ||
| if windll is not None: | ||
| winterm = WinTerm() | ||
| winterm = WinTerm() if windll is not None else None | ||
|
|
||
|
|
||
| def is_a_tty(stream): | ||
|
|
@@ -182,10 +180,7 @@ def call_win32(self, command, params): | |
| func = winterm.erase_data | ||
| func(params, on_stderr=self.on_stderr) | ||
| elif command == 'A': | ||
| if params == () or params == None: | ||
| num_rows = 1 | ||
| else: | ||
| num_rows = params[0] | ||
| num_rows = 1 if params == () or params is None else params[0] | ||
|
Comment on lines
-185
to
+183
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
|
||
| func = winterm.cursor_up | ||
| func(num_rows, on_stderr=self.on_stderr) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,9 +61,7 @@ def style(self, style=None, on_stderr=False): | |
| def set_console(self, attrs=None, on_stderr=False): | ||
| if attrs is None: | ||
| attrs = self.get_attrs() | ||
| handle = win32.STDOUT | ||
| if on_stderr: | ||
| handle = win32.STDERR | ||
| handle = win32.STDERR if on_stderr else win32.STDOUT | ||
|
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
|
||
| win32.SetConsoleTextAttribute(handle, attrs) | ||
|
|
||
| def get_position(self, handle): | ||
|
|
@@ -79,17 +77,13 @@ def set_cursor_position(self, position=None, on_stderr=False): | |
| #I'm not currently tracking the position, so there is no default. | ||
| #position = self.get_position() | ||
| return | ||
| handle = win32.STDOUT | ||
| if on_stderr: | ||
| handle = win32.STDERR | ||
| handle = win32.STDERR if on_stderr else win32.STDOUT | ||
|
Comment on lines
-82
to
+80
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
|
||
| win32.SetConsoleCursorPosition(handle, position) | ||
|
|
||
| def cursor_up(self, num_rows=0, on_stderr=False): | ||
| if num_rows == 0: | ||
| return | ||
| handle = win32.STDOUT | ||
| if on_stderr: | ||
| handle = win32.STDERR | ||
| handle = win32.STDERR if on_stderr else win32.STDOUT | ||
|
Comment on lines
-90
to
+86
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
|
||
| position = self.get_position(handle) | ||
| adjusted_position = (position.Y - num_rows, position.X) | ||
| self.set_cursor_position(adjusted_position, on_stderr) | ||
|
|
@@ -104,9 +98,7 @@ def erase_data(self, mode=0, on_stderr=False): | |
| # and to do so relative to the cursor position. | ||
| if mode[0] not in (2,): | ||
| return | ||
| handle = win32.STDOUT | ||
| if on_stderr: | ||
| handle = win32.STDERR | ||
| handle = win32.STDERR if on_stderr else win32.STDOUT | ||
|
Comment on lines
-107
to
+101
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
|
||
| # here's where we'll home the cursor | ||
| coord_screen = win32.COORD(0,0) | ||
| csbi = win32.GetConsoleScreenBufferInfo(handle) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| #!/usr/bin/env python | ||
| """fips main entry""" | ||
|
|
||
| import os | ||
| import sys | ||
| from mod import fips | ||
| fips_path = os.path.dirname(os.path.abspath(__file__)) | ||
| proj_path = fips_path | ||
| fips.run(fips_path, proj_path, sys.argv) | ||
| fips.run(proj_path, proj_path, sys.argv) | ||
|
Comment on lines
+3
to
+9
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. Lines
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,11 @@ | |
| Env = {} | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def error(msg) : | ||
| def error(msg): | ||
| ''' | ||
| Just print a simple error message and return with error code 10. | ||
| ''' | ||
| print("ERROR: {}".format(msg)) | ||
| print(f"ERROR: {msg}") | ||
|
Comment on lines
-11
to
+15
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
|
||
| sys.exit(10) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
|
|
@@ -23,37 +23,37 @@ def setErrorLocation(filePath, lineNumber) : | |
| LineNumber = lineNumber | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def fmtError(msg, terminate=True) : | ||
| def fmtError(msg, terminate=True): | ||
| ''' | ||
| Print an error message formatted so that IDEs can parse them, | ||
| and return with error code 10. | ||
| ''' | ||
| if platform.system() == 'Windows' : | ||
| print('{}({}): error: {}'.format(FilePath, LineNumber + 1, msg)) | ||
| else : | ||
| print('{}:{}:0: error: {}\n'.format(FilePath, LineNumber + 1, msg)) | ||
| if platform.system() == 'Windows': | ||
| print(f'{FilePath}({LineNumber + 1}): error: {msg}') | ||
| else: | ||
| print(f'{FilePath}:{LineNumber + 1}:0: error: {msg}\n') | ||
|
Comment on lines
-26
to
+34
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
|
||
| if terminate: | ||
| sys.exit(10) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def fmtWarning(msg) : | ||
| def fmtWarning(msg): | ||
| ''' | ||
| Print an warning message formatted so that IDEs can parse them. | ||
| ''' | ||
| if platform.system() == 'Windows' : | ||
| print('{}({}): warning: {}'.format(FilePath, LineNumber + 1, msg)) | ||
| else : | ||
| print('{}:{}:0: warning: {}\n'.format(FilePath, LineNumber + 1, msg)) | ||
| if platform.system() == 'Windows': | ||
| print(f'{FilePath}({LineNumber + 1}): warning: {msg}') | ||
| else: | ||
| print(f'{FilePath}:{LineNumber + 1}:0: warning: {msg}\n') | ||
|
Comment on lines
-39
to
+46
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 fileVersionDirty(filePath, version) : | ||
| def fileVersionDirty(filePath, version): | ||
| ''' | ||
| Reads the first 4 lines of a file, checks whether there's an | ||
| $$version:X statemenet in it, returns False if the version | ||
| number in the file is equal to the arg version. | ||
| ''' | ||
| f = open(filePath, 'r') | ||
| for i in range(0,4) : | ||
| for _ in range(0,4): | ||
|
Comment on lines
-49
to
+56
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
|
||
| line = f.readline() | ||
| startIndex = line.find('#version:') | ||
| if startIndex != -1 : | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ | |
| } | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def get_sdk_dir(fips_dir) : | ||
| return util.get_workspace_dir(fips_dir) + '/fips-sdks/android' | ||
| def get_sdk_dir(fips_dir): | ||
| return f'{util.get_workspace_dir(fips_dir)}/fips-sdks/android' | ||
|
Comment on lines
-30
to
+31
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 check_exists(fips_dir) : | ||
|
|
@@ -37,15 +37,15 @@ def check_exists(fips_dir) : | |
|
|
||
| #------------------------------------------------------------------------------- | ||
| def get_adb_path(fips_dir): | ||
| return get_sdk_dir(fips_dir) + '/platform-tools/adb' | ||
| return f'{get_sdk_dir(fips_dir)}/platform-tools/adb' | ||
|
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 get_tools_url() : | ||
| return tools_urls[util.get_host_platform()] | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def get_tools_archive_path(fips_dir): | ||
| return get_sdk_dir(fips_dir) + '/' + tools_archives[util.get_host_platform()] | ||
| return f'{get_sdk_dir(fips_dir)}/{tools_archives[util.get_host_platform()]}' | ||
|
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
|
||
|
|
||
| #------------------------------------------------------------------------------- | ||
| # convert a cmake target into a valid Android package name, | ||
|
|
@@ -58,10 +58,10 @@ def target_to_package_name(target): | |
|
|
||
| #------------------------------------------------------------------------------- | ||
| def install_package(fips_dir, pkg): | ||
| log.colored(log.BLUE, '>>> install Android SDK package: {}'.format(pkg)) | ||
| sdkmgr_dir = get_sdk_dir(fips_dir) + '/tools/bin/' | ||
| sdkmgr_path = sdkmgr_dir + 'sdkmanager' | ||
| cmd = '{} --verbose {}'.format(sdkmgr_path, pkg) | ||
| log.colored(log.BLUE, f'>>> install Android SDK package: {pkg}') | ||
| sdkmgr_dir = f'{get_sdk_dir(fips_dir)}/tools/bin/' | ||
| sdkmgr_path = f'{sdkmgr_dir}sdkmanager' | ||
| cmd = f'{sdkmgr_path} --verbose {pkg}' | ||
|
Comment on lines
-61
to
+64
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
|
||
| subprocess.call(cmd, cwd=sdkmgr_dir, shell=True) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
|
|
@@ -70,25 +70,23 @@ def ensure_sdk_dirs(fips_dir) : | |
| os.makedirs(get_sdk_dir(fips_dir)) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def uncompress(fips_dir, path) : | ||
| def uncompress(fips_dir, path): | ||
| # the python zip module doesn't preserve the executable flags, so just | ||
| # call unzip on Linux and OSX | ||
| if util.get_host_platform() in ['osx', 'linux']: | ||
| subprocess.call('unzip {}'.format(path), cwd=get_sdk_dir(fips_dir), shell=True) | ||
| subprocess.call(f'unzip {path}', cwd=get_sdk_dir(fips_dir), shell=True) | ||
|
Comment on lines
-73
to
+77
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
|
||
| else: | ||
| with zipfile.ZipFile(path, 'r') as archive: | ||
| archive.extractall(get_sdk_dir(fips_dir)) | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def compute_sha256(path, converter=lambda x: x, chunk_size=65536) : | ||
| def compute_sha256(path, converter=lambda x: x, chunk_size=65536): | ||
| if not os.path.isfile(path) : | ||
| return None | ||
| result = hashlib.sha256() | ||
| with open(path, 'rb') as file : | ||
| chunk = file.read(chunk_size) | ||
| while chunk : | ||
| with open(path, 'rb') as file: | ||
| while chunk := file.read(chunk_size): | ||
| result.update(converter(chunk)) | ||
| chunk = file.read(chunk_size) | ||
|
Comment on lines
-83
to
-91
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
|
||
| return result.hexdigest() | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
|
|
@@ -98,7 +96,7 @@ def strip_whitespace(bin_str) : | |
| return bin_str | ||
|
|
||
| #------------------------------------------------------------------------------- | ||
| def setup(fips_dir, proj_dir) : | ||
| def setup(fips_dir, proj_dir): | ||
|
Comment on lines
-101
to
+99
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
|
||
| """setup the Android SDK and NDK""" | ||
| log.colored(log.YELLOW, '=== setup Android SDK/NDK :') | ||
|
|
||
|
|
@@ -111,9 +109,9 @@ def setup(fips_dir, proj_dir) : | |
| # download the command line tools archive | ||
| tools_archive_path = get_tools_archive_path(fips_dir) | ||
| tools_url = get_tools_url() | ||
| log.info("downloading '{}'...".format(tools_url)) | ||
| log.info(f"downloading '{tools_url}'...") | ||
| urlretrieve(tools_url, tools_archive_path, util.url_download_hook) | ||
| log.info("\nunpacking '{}'...".format(tools_archive_path)) | ||
| log.info(f"\nunpacking '{tools_archive_path}'...") | ||
| uncompress(fips_dir, tools_archive_path) | ||
|
|
||
| # install the required SDK components through sdkmanager | ||
|
|
@@ -123,8 +121,8 @@ def setup(fips_dir, proj_dir) : | |
| install_package(fips_dir, 'ndk-bundle') | ||
|
|
||
| # check for potentially breaking changes in build setup | ||
| fips_cmake = fips_dir + '/cmake-toolchains/android.toolchain.orig' | ||
| ndk_cmake = get_sdk_dir(fips_dir) + '/ndk-bundle/build/cmake/android.toolchain.cmake' | ||
| fips_cmake = f'{fips_dir}/cmake-toolchains/android.toolchain.orig' | ||
| ndk_cmake = f'{get_sdk_dir(fips_dir)}/ndk-bundle/build/cmake/android.toolchain.cmake' | ||
| if compute_sha256(ndk_cmake, strip_whitespace) != compute_sha256(fips_cmake, strip_whitespace) : | ||
| log.warn('android.toolchain.cmake in fips might be outdated...') | ||
|
|
||
|
|
||
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.
Lines
10-12refactored with the following changes:elsebranch (introduce-default-else)assign-if-exp)