ryuslash  committed cfd21eb

Change the order of label file selection

If the environment variable `DISPASS_LABELFILE' exists, use it.
Otherwise, if the file in `$HOME/.dispass/' doesn't exist and either
environment variable `XDG_DATA_HOME' or `APPDATA' exist, use that.
If none of the above are true, use `$HOME/.dispass/'.

  • Participants
  • Parent commits 95c51ed
  • Branches master

Comments (0)

Files changed (1)

File dispass/

 import datetime
 import os
-from os.path import expanduser
+from os.path import expanduser, exists
 from dispass import __version__
     def getDefaultFileLocation(self):
         """Scan default labelfile paths"""
-        if os.getenv('DISPASS_LABELFILE'):
-            return os.getenv('DISPASS_LABELFILE')
-        elif os.getenv('XDG_CONFIG_HOME'):
-            return os.getenv('XDG_CONFIG_HOME') + '/dispass/labels'
-        elif os.getenv('APPDATA'):
-            return os.getenv('APPDATA') + '/dispass/labels'
+        label_env = os.getenv('DISPASS_LABELFILE')
+        std_env = os.getenv('XDG_DATA_HOME') or os.getenv('APPDATA')
+        home_file = expanduser('~/.dispass/labels')
+        if label_env:
+            return label_env
+        if not os.path.exists(home_file) and std_env:
+            return std_env + '/dispass/labels'
-            return '~/.config/dispass/labels'
+            return home_file
     def parse(self):
         '''Create dictionary {algorithm: (label, (length, seqno))}'''