From ed8bbd4e63d2e9db9501063bff51a3dae4e6fa4d Mon Sep 17 00:00:00 2001 From: Patrick Ulbrich Date: Wed, 20 Apr 2011 13:07:13 +0200 Subject: [PATCH] use XDG dirs --- mailnag | 12 +++++++++--- mailnag.py | 9 +++++---- mailnag_config | 29 +++++++++++++++++++---------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/mailnag b/mailnag index f696f5f..ff2c599 100755 --- a/mailnag +++ b/mailnag @@ -1,11 +1,17 @@ #!/bin/bash +CONFIG_HOME=$XDG_CONFIG_HOME +if [ "$CONFIG_HOME" == "" ]; then + CONFIG_HOME="$HOME/.config" +fi +config_dir="$CONFIG_HOME/mailnag" + main() { -if [ -f ~/.mailnag/mailnag.log ]; then - rm ~/.mailnag/mailnag.log +if [ -f "$config_dir/mailnag.log" ]; then + rm "$config_dir/mailnag.log" fi cd `dirname $0` -python mailnag.py autostarted >> ~/.mailnag/mailnag.log 2>&1 & +python mailnag.py autostarted >> "$config_dir/mailnag.log" 2>&1 & } connection() diff --git a/mailnag.py b/mailnag.py index 920dd7c..5353b17 100644 --- a/mailnag.py +++ b/mailnag.py @@ -41,6 +41,7 @@ import gettext from mailnag_config import Keyring #import cairo import signal +import xdg.BaseDirectory as bd gettext.bindtextdomain('mailnag', 'locale') @@ -431,14 +432,14 @@ def read_config(cfg_file): # read config file or create it def write_pid(): # write Mailnags's process id to file - pid_file = user_path + 'mailnag.pid' + pid_file = os.path.join(user_path, 'mailnag.pid') f = open(pid_file, 'w') f.write(str(os.getpid())) # get PID and write to file f.close() def delete_pid(): # delete file mailnag.pid - pid_file = user_path + 'mailnag.pid' + pid_file = os.path.join(user_path, 'mailnag.pid') if os.path.exists(pid_file): os.popen("rm " + pid_file) # delete it @@ -1271,14 +1272,14 @@ def main(): signal.signal(signal.SIGTERM, cleanup) try: - user_path = os.path.expanduser("~/.mailnag/") # set path to: "/home/user/.mailnag/" + user_path = os.path.join(bd.xdg_config_home, "mailnag") autostarted = False # default setting for command line argument cmdline = sys.argv # get command line arguments if len(cmdline) > 1: # do we have something in command line? if cmdline[1] == 'autostarted': autostarted = True write_pid() # write Mailnag's process id to file - cfg = read_config(user_path + 'mailnag.cfg') # get configuration from file + cfg = read_config(os.path.join(user_path, 'mailnag.cfg')) # get configuration from file accounts = Accounts() # create Accounts object if accounts.keyring_was_locked: firstcheck = False # required for correct sortorder in indi menu diff --git a/mailnag_config b/mailnag_config index 4d20363..e481e57 100755 --- a/mailnag_config +++ b/mailnag_config @@ -1,21 +1,30 @@ #!/bin/bash -if [ ! -d ~/.mailnag ]; then - mkdir ~/.mailnag +CONFIG_HOME=$XDG_CONFIG_HOME +if [ "$CONFIG_HOME" == "" ]; then + CONFIG_HOME="$HOME/.config" fi -if [ -f ~/.mailnag/mailnag_config.log ]; then - rm ~/.mailnag/mailnag_config.log +config_dir="$CONFIG_HOME/mailnag" + +if [ ! -d "$config_dir" ]; then + mkdir --parents "$config_dir" fi +if [ -f "$config_dir/mailnag_config.log" ]; then + rm "$config_dir/mailnag_config.log" +fi + cd `dirname $0` -python mailnag_config.py >> ~/.mailnag/mailnag_config.log 2>&1 + +python mailnag_config.py >> "$config_dir/mailnag_config.log" 2>&1 + if [ $? -eq 0 ]; then # Restart mailnag.py - if [ -f ~/.mailnag/mailnag.pid ]; then - kill $(cat ~/.mailnag/mailnag.pid) + if [ -f "$config_dir/mailnag.pid" ]; then + kill $(cat "$config_dir/mailnag.pid") fi - if [ -f ~/.mailnag/mailnag.log ]; then - rm ~/.mailnag/mailnag.log + if [ -f "$config_dir/mailnag.log" ]; then + rm "$config_dir/mailnag.log" fi - python mailnag.py >> ~/.mailnag/mailnag.log 2>&1 & + python mailnag.py >> "$config_dir/mailnag.log" 2>&1 & else echo mailnag-config discarded fi