deploy: convert to common.get_config()

717df09be0
This commit is contained in:
Hans-Christoph Steiner 2025-07-23 16:31:18 +02:00
parent 61842d626d
commit b6e73345e2
3 changed files with 38 additions and 54 deletions

View file

@ -40,7 +40,6 @@ import fdroidserver.github
from . import _, common, index from . import _, common, index
from .exception import FDroidException from .exception import FDroidException
config = None
start_timestamp = time.gmtime() start_timestamp = time.gmtime()
GIT_BRANCH = 'master' GIT_BRANCH = 'master'
@ -144,6 +143,7 @@ def update_remote_storage_with_rclone(
""" """
logging.debug(_('Using rclone to sync to "{name}"').format(name=awsbucket)) logging.debug(_('Using rclone to sync to "{name}"').format(name=awsbucket))
config = common.get_config()
rclone_config = config.get('rclone_config', []) rclone_config = config.get('rclone_config', [])
if rclone_config and isinstance(rclone_config, str): if rclone_config and isinstance(rclone_config, str):
rclone_config = [rclone_config] rclone_config = [rclone_config]
@ -271,6 +271,7 @@ def update_serverwebroot(serverwebroot, repo_section):
has a low resolution timestamp has a low resolution timestamp
""" """
config = common.get_config()
try: try:
subprocess.run(['rsync', '--version'], capture_output=True, check=True) subprocess.run(['rsync', '--version'], capture_output=True, check=True)
except Exception as e: except Exception as e:
@ -431,6 +432,7 @@ def update_servergitmirrors(servergitmirrors, repo_section):
""" """
from clint.textui import progress from clint.textui import progress
config = common.get_config()
if config.get('local_copy_dir') and not config.get('sync_from_local_copy_dir'): if config.get('local_copy_dir') and not config.get('sync_from_local_copy_dir'):
logging.debug( logging.debug(
_('Offline machine, skipping git mirror generation until `fdroid deploy`') _('Offline machine, skipping git mirror generation until `fdroid deploy`')
@ -1029,8 +1031,6 @@ def upload_to_github_releases_repo(repo_conf, release_infos, global_gh_token):
def main(): def main():
global config
parser = ArgumentParser() parser = ArgumentParser()
common.setup_global_opts(parser) common.setup_global_opts(parser)
parser.add_argument( parser.add_argument(

View file

@ -32,9 +32,10 @@ class DeployTest(unittest.TestCase):
self.testdir = self._td.name self.testdir = self._td.name
fdroidserver.common.options = mock.Mock() fdroidserver.common.options = mock.Mock()
fdroidserver.deploy.config = {} fdroidserver.common.get_config()
def tearDown(self): def tearDown(self):
fdroidserver.common.config = None
self._td.cleanup() self._td.cleanup()
def test_update_serverwebroots_bad_None(self): def test_update_serverwebroots_bad_None(self):
@ -64,7 +65,6 @@ class DeployTest(unittest.TestCase):
# setup parameters for this test run # setup parameters for this test run
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.deploy.config['make_current_version_link'] = False
dest_apk0 = url0 / fake_apk dest_apk0 = url0 / fake_apk
dest_apk1 = url1 / fake_apk dest_apk1 = url1 / fake_apk
@ -120,9 +120,9 @@ class DeployTest(unittest.TestCase):
# setup parameters for this test run # setup parameters for this test run
awsbucket = 'test_bucket_folder' awsbucket = 'test_bucket_folder'
fdroidserver.deploy.config['awsbucket'] = awsbucket fdroidserver.common.config['awsbucket'] = awsbucket
fdroidserver.deploy.config['rclone_config'] = 'test-local-config' fdroidserver.common.config['rclone_config'] = 'test-local-config'
fdroidserver.deploy.config['path_to_custom_rclone_config'] = str(rclone_file) fdroidserver.common.config['path_to_custom_rclone_config'] = str(rclone_file)
fdroidserver.common.options = VerboseFalseOptions fdroidserver.common.options = VerboseFalseOptions
# write out destination path # write out destination path
@ -163,9 +163,9 @@ class DeployTest(unittest.TestCase):
# setup parameters for this test run # setup parameters for this test run
awsbucket = 'test_bucket_folder' awsbucket = 'test_bucket_folder'
fdroidserver.deploy.config['awsbucket'] = awsbucket fdroidserver.common.config['awsbucket'] = awsbucket
fdroidserver.deploy.config['rclone_config'] = 'test-local-config' fdroidserver.common.config['rclone_config'] = 'test-local-config'
fdroidserver.deploy.config['path_to_custom_rclone_config'] = str(rclone_file) fdroidserver.common.config['path_to_custom_rclone_config'] = str(rclone_file)
fdroidserver.common.options = VerboseFalseOptions fdroidserver.common.options = VerboseFalseOptions
# write out destination path # write out destination path
@ -224,7 +224,7 @@ class DeployTest(unittest.TestCase):
return 0 return 0
mock_call.side_effect = _mock_subprocess_call mock_call.side_effect = _mock_subprocess_call
fdroidserver.deploy.config = {'awsbucket': awsbucket} fdroidserver.common.config = {'awsbucket': awsbucket}
fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket) fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket)
mock_call.assert_called() mock_call.assert_called()
@ -243,7 +243,7 @@ class DeployTest(unittest.TestCase):
mock_call.side_effect = _mock_subprocess_call mock_call.side_effect = _mock_subprocess_call
fdroidserver.deploy.config = {'awsbucket': awsbucket} fdroidserver.common.config = {'awsbucket': awsbucket}
fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket) fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket)
self.maxDiff = None self.maxDiff = None
self.assertEqual( self.assertEqual(
@ -262,7 +262,6 @@ class DeployTest(unittest.TestCase):
@mock.patch('subprocess.check_output', _mock_rclone_config_file) @mock.patch('subprocess.check_output', _mock_rclone_config_file)
@mock.patch('subprocess.call') @mock.patch('subprocess.call')
def test_update_remote_storage_with_rclone_mock_rclone_config(self, mock_call): def test_update_remote_storage_with_rclone_mock_rclone_config(self, mock_call):
awsbucket = 'test_bucket_folder'
self.last_cmd = None self.last_cmd = None
def _mock_subprocess_call(cmd): def _mock_subprocess_call(cmd):
@ -271,10 +270,9 @@ class DeployTest(unittest.TestCase):
mock_call.side_effect = _mock_subprocess_call mock_call.side_effect = _mock_subprocess_call
fdroidserver.deploy.config = { awsbucket = 'test_bucket_folder'
'awsbucket': awsbucket, fdroidserver.common.config['awsbucket'] = awsbucket
'rclone_config': 'test_local_config', fdroidserver.common.config['rclone_config'] = 'test_local_config'
}
fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket) fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket)
self.maxDiff = None self.maxDiff = None
self.assertEqual( self.assertEqual(
@ -304,8 +302,8 @@ class DeployTest(unittest.TestCase):
Path('rclone.conf').write_text('placeholder, contents ignored') Path('rclone.conf').write_text('placeholder, contents ignored')
awsbucket = 'test_bucket_folder' awsbucket = 'test_bucket_folder'
fdroidserver.deploy.config['awsbucket'] = awsbucket fdroidserver.common.config['awsbucket'] = awsbucket
fdroidserver.deploy.config['rclone_config'] = config_name fdroidserver.common.config['rclone_config'] = config_name
fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket) fdroidserver.deploy.update_remote_storage_with_rclone('repo', awsbucket)
self.maxDiff = None self.maxDiff = None
self.assertEqual( self.assertEqual(
@ -339,7 +337,6 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options = mock.Mock() fdroidserver.common.options = mock.Mock()
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.deploy.config['make_current_version_link'] = False
dest_apk = Path(url) / fake_apk dest_apk = Path(url) / fake_apk
dest_index = Path(url) / fake_index dest_index = Path(url) / fake_index
@ -366,7 +363,6 @@ class DeployTest(unittest.TestCase):
# setup parameters for this test run # setup parameters for this test run
fdroidserver.common.options = mock.Mock() fdroidserver.common.options = mock.Mock()
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.deploy.config['make_current_version_link'] = False
dest_apk = Path(url) / fake_apk dest_apk = Path(url) / fake_apk
dest_index = Path(url) / fake_index dest_index = Path(url) / fake_index
@ -396,7 +392,7 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.verbose = False fdroidserver.common.options.verbose = False
fdroidserver.common.options.quiet = True fdroidserver.common.options.quiet = True
fdroidserver.common.options.index_only = False fdroidserver.common.options.index_only = False
fdroidserver.deploy.config = {'make_current_version_link': True} fdroidserver.common.config['make_current_version_link'] = True
url = "example.com:/var/www/fdroid" url = "example.com:/var/www/fdroid"
repo_section = 'repo' repo_section = 'repo'
@ -504,7 +500,7 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.verbose = False fdroidserver.common.options.verbose = False
fdroidserver.common.options.quiet = True fdroidserver.common.options.quiet = True
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.deploy.config['make_current_version_link'] = True fdroidserver.common.config['make_current_version_link'] = True
url = "example.com:/var/www/fdroid" url = "example.com:/var/www/fdroid"
repo_section = 'repo' repo_section = 'repo'
@ -603,7 +599,7 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.quiet = False fdroidserver.common.options.quiet = False
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.common.options.index_only = False fdroidserver.common.options.index_only = False
fdroidserver.deploy.config = {'identity_file': './id_rsa'} fdroidserver.common.config = {'identity_file': './id_rsa'}
url = "example.com:/var/www/fdroid" url = "example.com:/var/www/fdroid"
repo_section = 'archive' repo_section = 'archive'
@ -623,7 +619,7 @@ class DeployTest(unittest.TestCase):
'--verbose', '--verbose',
'-e', '-e',
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
+ fdroidserver.deploy.config['identity_file'], + fdroidserver.common.config['identity_file'],
'--exclude', '--exclude',
'archive/altstore-index.json', 'archive/altstore-index.json',
'--exclude', '--exclude',
@ -669,7 +665,7 @@ class DeployTest(unittest.TestCase):
'--verbose', '--verbose',
'-e', '-e',
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
+ fdroidserver.deploy.config['identity_file'], + fdroidserver.common.config['identity_file'],
'archive', 'archive',
url, url,
], ],
@ -690,8 +686,7 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.verbose = True fdroidserver.common.options.verbose = True
fdroidserver.common.options.quiet = False fdroidserver.common.options.quiet = False
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
fdroidserver.deploy.config['identity_file'] = './id_rsa' fdroidserver.common.config['identity_file'] = './id_rsa'
fdroidserver.deploy.config['make_current_version_link'] = False
url = "example.com:/var/www/fdroid" url = "example.com:/var/www/fdroid"
repo_section = 'archive' repo_section = 'archive'
@ -711,7 +706,7 @@ class DeployTest(unittest.TestCase):
'--verbose', '--verbose',
'-e', '-e',
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
+ fdroidserver.deploy.config['identity_file'], + fdroidserver.common.config['identity_file'],
'archive/altstore-index.json', 'archive/altstore-index.json',
'archive/altstore-index.json.asc', 'archive/altstore-index.json.asc',
'archive/entry.jar', 'archive/entry.jar',
@ -741,7 +736,7 @@ class DeployTest(unittest.TestCase):
'--verbose', '--verbose',
'-e', '-e',
'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i ' 'ssh -oBatchMode=yes -oIdentitiesOnly=yes -i '
+ fdroidserver.deploy.config['identity_file'], + fdroidserver.common.config['identity_file'],
"example.com:/var/www/fdroid/archive/", "example.com:/var/www/fdroid/archive/",
], ],
) )
@ -793,10 +788,6 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.verbose = False fdroidserver.common.options.verbose = False
fdroidserver.common.options.quiet = True fdroidserver.common.options.quiet = True
config = {}
fdroidserver.common.fill_config_defaults(config)
fdroidserver.deploy.config = config
os.chdir(self.testdir) os.chdir(self.testdir)
repo_section = 'repo' repo_section = 'repo'
@ -807,7 +798,8 @@ class DeployTest(unittest.TestCase):
remote_git_repo = git.Repo.init( remote_git_repo = git.Repo.init(
remote_repo, initial_branch=initial_branch, bare=True remote_repo, initial_branch=initial_branch, bare=True
) )
fdroidserver.deploy.config["servergitmirrors"] = [{"url": str(remote_repo)}] fdroidserver.common.get_config()
fdroidserver.common.config["servergitmirrors"] = [{"url": str(remote_repo)}]
os.chdir(self.testdir) os.chdir(self.testdir)
repo = Path('repo') repo = Path('repo')
@ -820,7 +812,7 @@ class DeployTest(unittest.TestCase):
fp.write('not a real one, but has the right filename') fp.write('not a real one, but has the right filename')
fdroidserver.deploy.update_servergitmirrors( fdroidserver.deploy.update_servergitmirrors(
fdroidserver.deploy.config["servergitmirrors"], repo_section fdroidserver.common.config["servergitmirrors"], repo_section
) )
verify_repo = remote_git_repo.clone( verify_repo = remote_git_repo.clone(
@ -844,10 +836,6 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.verbose = False fdroidserver.common.options.verbose = False
fdroidserver.common.options.quiet = True fdroidserver.common.options.quiet = True
config = {}
fdroidserver.common.fill_config_defaults(config)
fdroidserver.deploy.config = config
os.chdir(self.testdir) os.chdir(self.testdir)
repo_section = 'repo' repo_section = 'repo'
@ -858,7 +846,7 @@ class DeployTest(unittest.TestCase):
remote_git_repo = git.Repo.init( remote_git_repo = git.Repo.init(
remote_repo, initial_branch=initial_branch, bare=True remote_repo, initial_branch=initial_branch, bare=True
) )
fdroidserver.deploy.config["servergitmirrors"] = [ fdroidserver.common.config["servergitmirrors"] = [
{"url": str(remote_repo), "index_only": True} {"url": str(remote_repo), "index_only": True}
] ]
@ -873,7 +861,7 @@ class DeployTest(unittest.TestCase):
fp.write('not a real one, but has the right filename') fp.write('not a real one, but has the right filename')
fdroidserver.deploy.update_servergitmirrors( fdroidserver.deploy.update_servergitmirrors(
fdroidserver.deploy.config["servergitmirrors"], repo_section fdroidserver.common.config["servergitmirrors"], repo_section
) )
verify_repo = remote_git_repo.clone( verify_repo = remote_git_repo.clone(
@ -905,10 +893,6 @@ class DeployTest(unittest.TestCase):
fdroidserver.common.options.quiet = True fdroidserver.common.options.quiet = True
fdroidserver.common.options.identity_file = None fdroidserver.common.options.identity_file = None
config = {}
fdroidserver.common.fill_config_defaults(config)
fdroidserver.deploy.config = config
repo_section = 'repo' repo_section = 'repo'
initial_branch = fdroidserver.deploy.GIT_BRANCH initial_branch = fdroidserver.deploy.GIT_BRANCH

View file

@ -75,7 +75,6 @@ class IntegrationTest(unittest.TestCase):
self.testdir = mkdir_testfiles(WORKSPACE, self) self.testdir = mkdir_testfiles(WORKSPACE, self)
self.tmp_repo_root = self.testdir / "fdroid" self.tmp_repo_root = self.testdir / "fdroid"
self.tmp_repo_root.mkdir(parents=True) self.tmp_repo_root.mkdir(parents=True)
deploy.config = {}
os.chdir(self.tmp_repo_root) os.chdir(self.tmp_repo_root)
def tearDown(self): def tearDown(self):
@ -1611,10 +1610,11 @@ class IntegrationTest(unittest.TestCase):
rclone_config.write(configfile) rclone_config.write(configfile)
# set up config for run # set up config for run
common.get_config()
awsbucket = "test-bucket" awsbucket = "test-bucket"
deploy.config['awsbucket'] = awsbucket common.config['awsbucket'] = awsbucket
deploy.config['rclone_config'] = "test-minio-config" common.config['rclone_config'] = "test-minio-config"
deploy.config['path_to_custom_rclone_config'] = str(rclone_file) common.config['path_to_custom_rclone_config'] = str(rclone_file)
common.options = VerboseFalseOptions common.options = VerboseFalseOptions
# call function # call function
@ -1667,9 +1667,9 @@ class IntegrationTest(unittest.TestCase):
# set up config for run # set up config for run
awsbucket = "test-bucket" awsbucket = "test-bucket"
deploy.config['awsbucket'] = awsbucket common.config['awsbucket'] = awsbucket
deploy.config['rclone_config'] = "test-minio-config" common.config['rclone_config'] = "test-minio-config"
deploy.config['path_to_custom_rclone_config'] = str(rclone_file) common.config['path_to_custom_rclone_config'] = str(rclone_file)
common.options = VerboseFalseOptions common.options = VerboseFalseOptions
# call function # call function