Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def copy_with_filtering(
src_dir_or_file, dest_dir, replacements=None, files_to_filter=None,
exclude=None, placeholder='${%s}'
):
"""
Copy the given file or directory to the given destination, optionally
applying filtering.
"""
if replacements is None:
replacements = SETTINGS
if files_to_filter is None:
files_to_filter = []
if exclude is None:
exclude = []
to_copy = _get_files_to_copy(src_dir_or_file, dest_dir, exclude)
to_filter = _paths(files_to_filter)
for src, dest in to_copy:
makedirs(dirname(dest), exist_ok=True)
if files_to_filter is None or src in to_filter:
_copy_with_filtering(src, dest, replacements, placeholder)
else:
copy(src, dest)
def _generate_runtime_hook():
makedirs(path('target/PyInstaller'), exist_ok=True)
module = fbs_runtime._frozen
hook_path = path('target/PyInstaller/fbs_pyinstaller_hook.py')
with open(hook_path, 'w') as f:
# Inject public settings such as "version" into the binary, so
# they're available at run time:
f.write('\n'.join([
'import importlib',
'module = importlib.import_module(%r)' % module.__name__,
'module.BUILD_SETTINGS = %r' % filter_public_settings(SETTINGS)
]))
return hook_path
"sudo apt-get install " + pkg_name
)
message += '\nIf they already have your app installed, they can ' \
'force an immediate update via:\n'
message += format_commands(
'sudo apt-get update '
'-o Dir::Etc::sourcelist="/etc/apt/sources.list.d/%s.list" '
'-o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"'
% pkg_name,
'sudo apt-get install --only-upgrade ' + pkg_name
)
elif is_arch_linux():
message += format_commands(
"curl -O %s && " % url('public-key.gpg') +
"sudo pacman-key --add public-key.gpg && " +
"sudo pacman-key --lsign-key %s && " % SETTINGS['gpg_key'] +
"rm public-key.gpg",
"echo -e '\\n[%s]\\nServer = %s' | sudo tee -a /etc/pacman.conf"
% (app_name, repo_url),
"sudo pacman -Syu " + pkg_name
)
message += '\nIf they already have your app installed, they can ' \
'force an immediate update via:\n'
message += format_commands('sudo pacman -Syu --needed ' + pkg_name)
elif is_fedora():
message += format_commands(
"sudo rpm -v --import " + url('public-key.gpg'),
"sudo dnf config-manager --add-repo %s/%s.repo"
% (repo_url, app_name),
"sudo dnf install " + pkg_name
)
message += "\n(On CentOS, replace 'dnf' by 'yum' and " \
def freeze_windows(debug=False):
args = []
if not (debug or SETTINGS['show_console_window']):
# The --windowed flag below prevents us from seeing any console output.
# We therefore only add it when we're not debugging.
args.append('--windowed')
args.extend(['--icon', path('src/main/icons/Icon.ico')])
run_pyinstaller(args, debug)
_restore_corrupted_python_dlls()
_generate_resources()
copy(path('src/main/icons/Icon.ico'), path('${freeze_dir}'))
_add_missing_dlls()
def preset_gpg_passphrase():
# Ensure gpg-agent is running:
run(
['gpg-agent', '--daemon', '--use-standard-socket', '-q'],
stdout=DEVNULL, stderr=DEVNULL
)
gpg_key = SETTINGS['gpg_key']
try:
keygrip = _get_keygrip(gpg_key)
except GpgDoesNotSupportKeygrip:
# Old GPG versions don't support keygrips; They use the fingerprint
# instead:
keygrip = gpg_key
check_call([
SETTINGS['gpg_preset_passphrase'], '--preset', '--passphrase',
SETTINGS['gpg_pass'], keygrip
], stdout=DEVNULL)
path_in_docker = lambda p: '/root/%s/%s' % (SETTINGS['app_name'], p)
return {path(src): path_in_docker(dest) for src, dest in result.items()}
def run_pyinstaller(extra_args=None, debug=False):
if extra_args is None:
extra_args = []
app_name = SETTINGS['app_name']
# Would like log level WARN when not debugging. This works fine for
# PyInstaller 3.3. However, for 3.4, it gives confusing warnings
# "hidden import not found". So use ERROR instead.
log_level = 'DEBUG' if debug else 'ERROR'
args = [
'pyinstaller',
'--name', app_name,
'--noupx',
'--log-level', log_level,
'--noconfirm'
]
for hidden_import in SETTINGS['hidden_imports']:
args.extend(['--hidden-import', hidden_import])
args.extend(extra_args)
args.extend([
'--distpath', path('target'),
'--specpath', path('target/PyInstaller'),
'--workpath', path('target/PyInstaller')
])
args.extend(['--additional-hooks-dir', join(dirname(__file__), 'hooks')])
if debug:
args.extend(['--debug', 'all'])
if is_mac():
# Force generation of an .app bundle. Otherwise, PyInstaller skips
# it when --debug is given.
args.append('-w')
hook_path = _generate_runtime_hook()
args.extend(['--runtime-hook', hook_path])
def sign_installer_arch():
installer = path('target/${installer}')
# Prevent GPG from prompting us for the passphrase when signing:
preset_gpg_passphrase()
check_call(
['gpg', '--batch', '--yes', '-u', SETTINGS['gpg_key'],
'--output', installer + '.sig', '--detach-sig', installer],
stdout=DEVNULL
)
def _copy(path_fn, src, dst): # Used by several other internal fbs modules
src = path_fn(src)
if exists(src):
filter_ = [path_fn(f) for f in SETTINGS['files_to_filter']]
copy_with_filtering(src, dst, files_to_filter=filter_)
return True
return False
def create_installer_mac():
app_name = SETTINGS['app_name']
dest = path('target/${installer}')
dest_existed = exists(dest)
if dest_existed:
dest_bu = dest + '.bu'
replace(dest, dest_bu)
try:
check_call([
join(dirname(__file__), 'create-dmg', 'create-dmg'),
'--volname', app_name,
'--app-drop-link', '170', '10',
'--icon', app_name + '.app', '0', '10',
dest,
path('${freeze_dir}')
], stdout=DEVNULL)
except:
if dest_existed: