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
9 changes: 2 additions & 7 deletions colorama/ansitowin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Lines 10-12 refactored with the following changes:



def is_a_tty(stream):
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function AnsiToWin32.call_win32 refactored with the following changes:

func = winterm.cursor_up
func(num_rows, on_stderr=self.on_stderr)

16 changes: 4 additions & 12 deletions colorama/winterm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function WinTerm.set_console refactored with the following changes:

win32.SetConsoleTextAttribute(handle, attrs)

def get_position(self, handle):
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function WinTerm.set_cursor_position refactored with the following changes:

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
Copy link
Author

Choose a reason for hiding this comment

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

Function WinTerm.cursor_up refactored with the following changes:

position = self.get_position(handle)
adjusted_position = (position.Y - num_rows, position.X)
self.set_cursor_position(adjusted_position, on_stderr)
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function WinTerm.erase_data refactored with the following changes:

# here's where we'll home the cursor
coord_screen = win32.COORD(0,0)
csbi = win32.GetConsoleScreenBufferInfo(handle)
Expand Down
3 changes: 2 additions & 1 deletion fips
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
Copy link
Author

Choose a reason for hiding this comment

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

Lines 8-8 refactored with the following changes:


28 changes: 14 additions & 14 deletions generators/genutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function error refactored with the following changes:

sys.exit(10)

#-------------------------------------------------------------------------------
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function fmtError refactored with the following changes:

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
Copy link
Author

Choose a reason for hiding this comment

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

Function fmtWarning refactored with the following changes:


#-------------------------------------------------------------------------------
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
Copy link
Author

Choose a reason for hiding this comment

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

Function fileVersionDirty refactored with the following changes:

line = f.readline()
startIndex = line.find('#version:')
if startIndex != -1 :
Expand Down
38 changes: 18 additions & 20 deletions mod/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function get_sdk_dir refactored with the following changes:


#-------------------------------------------------------------------------------
def check_exists(fips_dir) :
Expand All @@ -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'
Copy link
Author

Choose a reason for hiding this comment

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

Function get_adb_path refactored with the following changes:


#-------------------------------------------------------------------------------
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()]}'
Copy link
Author

Choose a reason for hiding this comment

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

Function get_tools_archive_path refactored with the following changes:


#-------------------------------------------------------------------------------
# convert a cmake target into a valid Android package name,
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function install_package refactored with the following changes:

subprocess.call(cmd, cwd=sdkmgr_dir, shell=True)

#-------------------------------------------------------------------------------
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function uncompress refactored with the following changes:

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
Copy link
Author

Choose a reason for hiding this comment

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

Function compute_sha256 refactored with the following changes:

return result.hexdigest()

#-------------------------------------------------------------------------------
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

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

Function setup refactored with the following changes:

"""setup the Android SDK and NDK"""
log.colored(log.YELLOW, '=== setup Android SDK/NDK :')

Expand All @@ -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
Expand All @@ -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...')

Expand Down
Loading