From 39b3b7793a75d66276e39a7f1a4d6595a34c4229 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Fri, 17 Dec 2021 10:58:10 +0000 Subject: [PATCH] Add support for IA_CONFIG_FILE environment variable --- ia-upload-stream | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ia-upload-stream b/ia-upload-stream index 4136a58..ed0d5f0 100755 --- a/ia-upload-stream +++ b/ia-upload-stream @@ -41,15 +41,19 @@ class PreventCompletionError(UploadError): def get_ia_access_secret(configFile = None): if configFile is None: - # This part of the code is identical (except for style changes) to the one in internetarchive and was written from scratch by JustAnotherArchivist in May 2021. + # This part of the code is identical (except for style changes) to the one in internetarchive and was written from scratch by JustAnotherArchivist in May and December 2021. + candidates = [] + if os.environ.get('IA_CONFIG_FILE'): + candidates.append(os.environ['IA_CONFIG_FILE']) xdgConfigHome = os.environ.get('XDG_CONFIG_HOME') if not xdgConfigHome or not os.path.isabs(xdgConfigHome) or not os.path.isdir(xdgConfigHome): # Per the XDG Base Dir specification, this should be $HOME/.config. Unfortunately, $HOME does not exist on all systems. Therefore, we use ~/.config here. # On a POSIX-compliant system, where $HOME must always be set, the XDG spec will be followed precisely. xdgConfigHome = os.path.join(os.path.expanduser('~'), '.config') - for candidate in [os.path.join(xdgConfigHome, 'internetarchive', 'ia.ini'), - os.path.join(os.path.expanduser('~'), '.config', 'ia.ini'), - os.path.join(os.path.expanduser('~'), '.ia')]: + candidates.append(os.path.join(xdgConfigHome, 'internetarchive', 'ia.ini')) + candidates.append(os.path.join(os.path.expanduser('~'), '.config', 'ia.ini')) + candidates.append(os.path.join(os.path.expanduser('~'), '.ia')) + for candidate in candidates: if os.path.isfile(candidate): configFile = candidate break