mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 15:00:30 +03:00
split out options from read_config()
There is no longer any reason for these to be intertwined. This deliberately avoids touching some files as much as possible because they are super tangled and due to be replaced. Those files are: * fdroidserver/build.py * fdroidserver/update.py # Conflicts: # tests/testcommon.py # Conflicts: # fdroidserver/btlog.py # fdroidserver/import_subcommand.py
This commit is contained in:
parent
685efa23d4
commit
18f3acc32e
53 changed files with 317 additions and 265 deletions
|
|
@ -191,6 +191,34 @@ default_config = {
|
|||
}
|
||||
|
||||
|
||||
def get_options():
|
||||
"""Return options as set up by parse_args().
|
||||
|
||||
This provides an easy way to get the global instance without
|
||||
having to think about very confusing import and submodule
|
||||
visibility. The code should be probably refactored so it does not
|
||||
need this. If each individual option value was always passed to
|
||||
functions as args, for example.
|
||||
|
||||
https://docs.python.org/3/reference/import.html#submodules
|
||||
|
||||
"""
|
||||
return fdroidserver.common.options
|
||||
|
||||
|
||||
def parse_args(parser):
|
||||
"""Call parser.parse_args(), store result in module-level variable and return it.
|
||||
|
||||
This is needed to set up the copy of the options instance in the
|
||||
fdroidserver.common module. A subcommand only needs to call this
|
||||
if it uses functions from fdroidserver.common that expect the
|
||||
"options" variable to be initialized.
|
||||
|
||||
"""
|
||||
fdroidserver.common.options = parser.parse_args()
|
||||
return fdroidserver.common.options
|
||||
|
||||
|
||||
def setup_global_opts(parser):
|
||||
try: # the buildserver VM might not have PIL installed
|
||||
from PIL import PngImagePlugin
|
||||
|
|
@ -373,7 +401,7 @@ def fill_config_defaults(thisconfig):
|
|||
thisconfig['gradle_version_dir'] = str(Path(thisconfig['cachedir']) / 'gradle')
|
||||
|
||||
|
||||
def get_config(opts=None):
|
||||
def get_config():
|
||||
"""Get the initalized, singleton config instance.
|
||||
|
||||
config and options are intertwined in read_config(), so they have
|
||||
|
|
@ -395,18 +423,16 @@ def get_config(opts=None):
|
|||
instance in fdroidserver.common.
|
||||
|
||||
"""
|
||||
global config, options
|
||||
global config
|
||||
|
||||
if config is not None:
|
||||
return config
|
||||
|
||||
read_config(opts=opts)
|
||||
read_config()
|
||||
|
||||
# make sure these values are available in common.py even if they didn't
|
||||
# declare global in a scope
|
||||
common.config = config
|
||||
if opts is not None:
|
||||
common.options = opts
|
||||
|
||||
return config
|
||||
|
||||
|
|
@ -439,7 +465,7 @@ def config_type_check(path, data):
|
|||
)
|
||||
|
||||
|
||||
def read_config(opts=None):
|
||||
def read_config():
|
||||
"""Read the repository config.
|
||||
|
||||
The config is read from config_file, which is in the current
|
||||
|
|
@ -458,13 +484,11 @@ def read_config(opts=None):
|
|||
in git, it makes sense to use a globally standard encoding.
|
||||
|
||||
"""
|
||||
global config, options
|
||||
global config
|
||||
|
||||
if config is not None:
|
||||
return config
|
||||
|
||||
options = opts
|
||||
|
||||
config = {}
|
||||
config_file = 'config.yml'
|
||||
old_config_file = 'config.py'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue