-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ApplicationContext#public_settings
This lets you access some build settings at runtime; Eg. public_settings['version']. What is available is controlled by the new setting "public_settings".
- Loading branch information
Showing
19 changed files
with
218 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from fbs import _defaults, path, LOADED_PROFILES | ||
from fbs import path, LOADED_PROFILES | ||
from fbs.resources import _copy | ||
from fbs_runtime._source import default_path | ||
|
||
def _generate_installer_resources(): | ||
for path_fn in _defaults.path, path: | ||
for path_fn in default_path, path: | ||
for profile in LOADED_PROFILES: | ||
_copy(path_fn, 'src/installer/' + profile, path('target/installer')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
from fbs_runtime import platform, FbsError | ||
from fbs_runtime.platform import is_mac | ||
from os.path import join, exists, realpath, dirname, pardir | ||
from pathlib import PurePath | ||
from fbs_runtime import platform | ||
from fbs_runtime.platform import is_ubuntu, is_linux, is_arch_linux, is_fedora | ||
|
||
import errno | ||
import inspect | ||
import os | ||
import sys | ||
def get_core_settings(project_dir): | ||
return { | ||
'project_dir': project_dir | ||
} | ||
|
||
class ResourceLocator: | ||
def __init__(self, resource_dirs): | ||
self._dirs = resource_dirs | ||
def locate(self, *rel_path): | ||
for resource_dir in self._dirs: | ||
resource_path = join(resource_dir, *rel_path) | ||
if exists(resource_path): | ||
return realpath(resource_path) | ||
raise FileNotFoundError( | ||
errno.ENOENT, 'Could not locate resource', os.sep.join(rel_path) | ||
) | ||
def get_default_profiles(): | ||
result = ['base'] | ||
# The "secret" profile lets the user store sensitive settings such as | ||
# passwords in src/build/settings/secret.json. When using Git, the user can | ||
# exploit this by adding secret.json to .gitignore, thus preventing it from | ||
# being uploaded to services such as GitHub. | ||
result.append('secret') | ||
result.append(platform.name().lower()) | ||
if is_linux(): | ||
if is_ubuntu(): | ||
result.append('ubuntu') | ||
elif is_arch_linux(): | ||
result.append('arch') | ||
elif is_fedora(): | ||
result.append('fedora') | ||
return result | ||
|
||
def get_resource_dirs_frozen(): | ||
app_dir = dirname(sys.executable) | ||
return [join(app_dir, pardir, 'Resources') if is_mac() else app_dir] | ||
|
||
def get_resource_dirs_source(appctxt_cls): | ||
project_dir = _get_project_base_dir(appctxt_cls) | ||
resources_dir = join(project_dir, 'src', 'main', 'resources') | ||
return [ | ||
join(resources_dir, platform.name().lower()), | ||
join(resources_dir, 'base'), | ||
join(project_dir, 'src', 'main', 'icons') | ||
] | ||
|
||
def _get_project_base_dir(appctxt_cls): | ||
class_file = inspect.getfile(appctxt_cls) | ||
p = PurePath(class_file) | ||
while p != p.parent: | ||
parent_names = [p.parents[2].name, p.parents[1].name, p.parent.name] | ||
if parent_names == ['src', 'main', 'python']: | ||
return str(p.parents[3]) | ||
p = p.parent | ||
raise FbsError( | ||
'Could not determine project base directory for %s. Is it in ' | ||
'src/main/python?' % appctxt_cls | ||
) | ||
def get_public_settings(settings): | ||
return {k: settings[k] for k in settings['public_settings']} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
This module contains functions that should only be called when running the | ||
frozen form of the app. | ||
""" | ||
|
||
from os.path import dirname, join, pardir | ||
from fbs_runtime.platform import is_mac | ||
|
||
import sys | ||
|
||
# The contents of this dictionary are injected via a PyInstaller runtime hook. | ||
# See: `fbs.freeze._PyInstallerRuntimehook`. | ||
PUBLIC_SETTINGS = {} | ||
|
||
def get_resource_dirs(): | ||
app_dir = dirname(sys.executable) | ||
return [join(app_dir, pardir, 'Resources') if is_mac() else app_dir] | ||
|
||
def load_public_settings(): | ||
return PUBLIC_SETTINGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from os.path import join, exists, realpath | ||
|
||
import errno | ||
import os | ||
|
||
class ResourceLocator: | ||
def __init__(self, resource_dirs): | ||
self._dirs = resource_dirs | ||
def locate(self, *rel_path): | ||
for resource_dir in self._dirs: | ||
resource_path = join(resource_dir, *rel_path) | ||
if exists(resource_path): | ||
return realpath(resource_path) | ||
raise FileNotFoundError( | ||
errno.ENOENT, 'Could not locate resource', os.sep.join(rel_path) | ||
) |
File renamed without changes.
Oops, something went wrong.