From d113aadcbcf163065bb1e43b6641ecaa8fc07c9c Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 4 Sep 2011 04:50:38 +0200 Subject: [PATCH 1/5] config & constants: Use constants for default locations. --- qasim/config.rb | 21 ++------------------- qasim/constants.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/qasim/config.rb b/qasim/config.rb index 81dd072..b25d8f7 100644 --- a/qasim/config.rb +++ b/qasim/config.rb @@ -20,27 +20,10 @@ module Qasim def initialize - user = if ENV['USER'] then - ENV['USER'] - else - raise "Environment variable 'USER' is missing!" - end - home_dir = if ENV['HOME'] then - ENV['HOME'] - else - "/home/" + user - end + @mnt_dir = File.join ENV['HOME'], "mnt" - xdg_dir = if ENV['XDG_CONFIG_HOME'] then - ENV['XDG_CONFIG_HOME'] - else - home_dir + '/.config' - end - - @mnt_dir = File.join home_dir, "mnt" - - @config_dir = xdg_dir + '/sshfs-mapper' + @config_dir = APP_CONFIG_DIR @config_file = nil @maps = [] @initialize_enable = false diff --git a/qasim/constants.rb b/qasim/constants.rb index 0ffc237..fd21c64 100644 --- a/qasim/constants.rb +++ b/qasim/constants.rb @@ -1,6 +1,13 @@ module Qasim APP_ICON_PATH = File.join QASIM_INCLUDE_DIR, "icons" - APP_SYSCONFIG_DIR = "/etc/qasim/maps.d" APP_NAME = "Qasim" APP_VERSION = "0.1" + + APP_SYSCONFIG_DIR = "/etc/qasim/maps.d" + + APP_CONFIG_DIR = if ENV['XDG_CONFIG_HOME'] then + File.join ENV['XDG_CONFIG_HOME'], 'qasim' + else + File.join ENV['HOME'], '.config', 'qasim' + end end From bfe5518b40b71193e032e16510da39bbfa3bf120 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 4 Sep 2011 04:51:29 +0200 Subject: [PATCH 2/5] qasim-gui: prepare for locking. --- bin/qasim-gui.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 04f2f3e..dd5219b 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -7,6 +7,7 @@ $VERBOSE = true require 'pp' require 'set' +require 'fcntl' QASIM_INCLUDE_DIR = "." $:.push QASIM_INCLUDE_DIR @@ -209,7 +210,27 @@ module Qasim # # def run + # create lock + have_lock = true + + lockfname = APP_CONFIG_DIR, "lock" + File.open lockfname, "w" do + unless f.flock File::LOCK_EX | File::LOCK_NB + warn "Another instance of %s is already running." % APP_NAME + exit 1 + end + f.flock File::LOCK_EX + end + + fd = IO::sysopen('/tmp/tempfile', + Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) + f = IO.open(fd) + f.syswrite("TEMP DATA") + f.close + masterpid = fh.gets @app.exec + ensure + fh.close end From 4df09954fa2c1e45aabff647fbe41319dc79e2e5 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 4 Sep 2011 05:06:23 +0200 Subject: [PATCH 3/5] Single instance lock is now functional. --- bin/qasim-gui.rb | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index dd5219b..22f6142 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -144,13 +144,13 @@ module Qasim @context_menu = Qt::Menu.new act_pref = Qt::Action.new _('&Preferences'), @context_menu - act_pref.setIcon( Qt::Icon::fromTheme("configure") ) + act_pref.setIcon( Qt::Icon::fromTheme("configure") ) rescue nil act_pref.setIconVisibleInMenu true act_pref.setEnabled false @context_menu.addAction act_pref; act_about = Qt::Action.new '&About', @context_menu - act_about.setIcon( Qt::Icon::fromTheme("help-about") ) + act_about.setIcon( Qt::Icon::fromTheme("help-about") ) rescue nil act_about.setIconVisibleInMenu true act_about.setEnabled false @context_menu.addAction act_about; @@ -158,7 +158,7 @@ module Qasim @context_menu.addSeparator act_quit = Qt::Action.new _('Quit'), @context_menu - act_quit.setIcon( Qt::Icon::fromTheme("application-exit") ) + act_quit.setIcon( Qt::Icon::fromTheme("application-exit") ) rescue nil act_quit.setIconVisibleInMenu true act_quit.connect(SIGNAL(:triggered)) { @app.quit } @context_menu.addAction act_quit @@ -213,24 +213,22 @@ module Qasim # create lock have_lock = true - lockfname = APP_CONFIG_DIR, "lock" - File.open lockfname, "w" do - unless f.flock File::LOCK_EX | File::LOCK_NB - warn "Another instance of %s is already running." % APP_NAME - exit 1 - end - f.flock File::LOCK_EX - end - - fd = IO::sysopen('/tmp/tempfile', + FileUtils.mkdir_p APP_CONFIG_DIR unless File.exist? APP_CONFIG_DIR + lockfname = File.join APP_CONFIG_DIR, "lock" + fd = IO::sysopen( lockfname, Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) f = IO.open(fd) - f.syswrite("TEMP DATA") + f.syswrite( "Process.pid\n" ) f.close - masterpid = fh.gets @app.exec + rescue Errno::EEXIST => e + warn "error: Another instance of %s is already running." + exit 1 ensure - fh.close + masterpid = File.read(lockfname).strip + if masterpid == Process.pid then + FileUtils.rm lockfname + end end From a2ce48dea425c0c8779c1a48f16472c9d8b02b23 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Wed, 7 Sep 2011 01:10:57 +0200 Subject: [PATCH 4/5] Updated debian changelog. --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index b30213b..7c754f2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +qasim (0.1.6) unstable; urgency=low + + * qasim-gui: handle QIcon::fromTheme NoMethodError exception when needed. + * qasim-gui: added single instance lock. + + -- Glenn Y. Rolland Wed, 07 Sep 2011 01:08:48 +0200 + qasim (0.1.5) unstable; urgency=low * map: Added missing require for fileutils. From 2bca81097940e590fea6a56c52fb8efbcf05626e Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 9 Sep 2011 01:22:36 +0200 Subject: [PATCH 5/5] qasim-gui: Fixed typo in error message. --- bin/qasim-gui.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 22f6142..5867c3d 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -222,7 +222,7 @@ module Qasim f.close @app.exec rescue Errno::EEXIST => e - warn "error: Another instance of %s is already running." + warn "error: Another instance of %s is already running." % APP_NAME exit 1 ensure masterpid = File.read(lockfname).strip