Use rumps.application_support instead of xdg paths. Also separated branding into config.py

Sun, 21 Jan 2018 14:56:56 +0000

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sun, 21 Jan 2018 14:56:56 +0000
changeset 33
91421eeb4426
parent 32
06fc14211ba9
child 34
9fce700d42de

Use rumps.application_support instead of xdg paths. Also separated branding into config.py

README.md file | annotate | diff | comparison | revisions
borgend.py file | annotate | diff | comparison | revisions
config.py file | annotate | diff | comparison | revisions
setup.py file | annotate | diff | comparison | revisions
ui.py file | annotate | diff | comparison | revisions
--- a/README.md	Sun Jan 21 14:34:35 2018 +0000
+++ b/README.md	Sun Jan 21 14:56:56 2018 +0000
@@ -9,13 +9,14 @@
 You will need to install the following non-standard Python packages:
 
  - [rumps](https://github.com/jaredks/rumps) (Ridiculously Uncomplicated macOS Python Statusbar apps)
- - [keyring](https://pypi.python.org/pypi/keyring)
+ - [keyring](https://pypi.python.org/pypi/keyring) to extracdt passphrases from the keychain
+<!-- - [xdg](https://pypi.python.org/pypi/xdg/3.0.0) for configuration file location -->
 
 For passphrase use authentication to work correctly, it is useful to create a standalone Mac app. This can be don with `py2app`. You can install it with
 
     pip install py2app
 
-(for alternatives see [py2app documentation](https://py2app.readthedocs.io/en/latest/install.html#installing-with-pip)). Then, to build the standalone app, run
+(for alternatives see [py2app documentation](https://py2app.readthedocs.io/en/latest/install.html)). Then, to build the standalone app, run
 
     python3 setup.py py2app
 
--- a/borgend.py	Sun Jan 21 14:34:35 2018 +0000
+++ b/borgend.py	Sun Jan 21 14:56:56 2018 +0000
@@ -25,7 +25,7 @@
 
 if __name__ == "__main__":
     #print(settings)
-    tray=BorgendTray("Borgend", backups);
+    tray=BorgendTray(backups);
     tray.run()
     pass
 
--- a/config.py	Sun Jan 21 14:34:35 2018 +0000
+++ b/config.py	Sun Jan 21 14:56:56 2018 +0000
@@ -6,7 +6,6 @@
 import yaml
 import io
 import os
-import xdg
 import string
 import logging
 from functools import reduce
@@ -37,6 +36,26 @@
     }
 }
 
+#
+# Branding
+#
+
+appname="borgend"
+appname_stylised="Borgend"
+
+#
+# Locations
+#
+
+if False:
+    import xdg
+    cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, appname, "config.yaml")
+    logs_location=os.path.join(xdg.XDG_DATA_HOME, appname, "logs")
+else:
+    import rumps
+    __base=rumps.application_support(appname)
+    cfgfile=os.path.join(__base, "config.yaml")
+    logs_location=os.path.join(__base, "logs")
 
 #
 # Type checking etc.
@@ -124,12 +143,10 @@
 
     return out
 
-cfgfile=os.path.join(xdg.XDG_CONFIG_HOME, "borgend", "config.yaml")
+if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)):
+    raise SystemExit("Configuration file required: %s" % cfgfile)
 
-logger.info("Reading configuration file %s" % cfgfile)
-
-if not (os.path.exists(cfgfile) and os.path.isfile(cfgfile)):
-    raise SystemExit('Configuration file required: {cfgfile}')
+logger.info("Reading configuration %s missing" % cfgfile)
 
 with io.open(cfgfile, 'r') as file:
     settings=expand_env(yaml.load(file), os.environ);
--- a/setup.py	Sun Jan 21 14:34:35 2018 +0000
+++ b/setup.py	Sun Jan 21 14:56:56 2018 +0000
@@ -7,7 +7,7 @@
     'plist': {
         'LSUIElement': True,
     },
-    'packages': ['rumps', 'keyring'],
+    'packages': ['rumps', 'keyring'], #, 'xdg'],
 }
 
 setup(
--- a/ui.py	Sun Jan 21 14:34:35 2018 +0000
+++ b/ui.py	Sun Jan 21 14:56:56 2018 +0000
@@ -7,7 +7,7 @@
 import datetime
 import logging
 from threading import Lock, Timer
-from config import settings
+from config import settings, appname_stylised
 import objc
 
 logger=logging.getLogger(__name__)
@@ -106,7 +106,7 @@
 
 
 class BorgendTray(rumps.App):
-    def __init__(self, name, backups):
+    def __init__(self, backups):
         self.lock=Lock()
         self.backups=backups
         self.statuses=[None]*len(backups)
@@ -180,7 +180,8 @@
             logger.debug("Opening notification for error %s '%s'",
                          msgid, errorlog['message'])
 
-            notification_workaround('Borgend', msgid, errorlog['message'])
+            notification_workaround(appname_stylised,
+                                    msgid, errorlog['message'])
 
     def my_quit(self, _):
         rumps.quit_application()
@@ -193,7 +194,8 @@
         except Exception as err:
             logger.debug("Opening notification for exception %s '%s'",
                          err.__class__.__name__, str(err))
-            notification_workaround('Borgend', err.__class__.__name__, str(err))
+            notification_workaround(appname_stylised,
+                                    err.__class__.__name__, str(err))
 
     @rumps.notifications
     def notification_center(data):

mercurial