Browse Source

Add support for IA_CONFIG_FILE environment variable

master
JustAnotherArchivist 2 years ago
parent
commit
39b3b7793a
1 changed files with 8 additions and 4 deletions
  1. +8
    -4
      ia-upload-stream

+ 8
- 4
ia-upload-stream View File

@@ -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


Loading…
Cancel
Save