From 9c6e2fda1e454b7d5fccd1a5525f38a9a27f4e1c Mon Sep 17 00:00:00 2001 From: David Whyte Date: Sat, 10 Sep 2011 00:33:12 +1000 Subject: [PATCH 01/14] Minor change to location of db on Linux. Should now persist across upgrades of packages --- houseagent/__init__.py | 2 +- setup.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/houseagent/__init__.py b/houseagent/__init__.py index 27dc32d..374c6d6 100644 --- a/houseagent/__init__.py +++ b/houseagent/__init__.py @@ -14,7 +14,7 @@ from win32com.shell import shellcon, shell db_path = os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0), 'HouseAgent', db_name) else: - db_path = os.path.join(sys.prefix, 'share', 'HouseAgent', db_name) + db_path = os.path.join(os.sep, 'etc', 'HouseAgent', db_name) if os.path.exists(db_path): # Production environment diff --git a/setup.py b/setup.py index 8fa0b0e..2ef8068 100644 --- a/setup.py +++ b/setup.py @@ -37,8 +37,7 @@ def find_package_files(workingdir, subdir): packages = ['houseagent','houseagent.core', 'houseagent.plugins', 'houseagent.utils', 'houseagent.pages'], package_data = {'houseagent': template_files}, scripts = ['HouseAgent.py'], - data_files = [('/etc/HouseAgent', ['HouseAgent.conf', 'specs/amqp0-8.xml']), - ('share/HouseAgent', ['houseagent.db'])], + data_files = [('/etc/HouseAgent', ['HouseAgent.conf', 'specs/amqp0-8.xml', 'houseagent.db'])], ) From 12fec47033d8fe30e0fdc1484fc5262f15586108 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Sun, 6 Nov 2011 21:10:52 +1000 Subject: [PATCH 02/14] Change dependency from RabbitMQ to ZeroMQ. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index cc217e7..9d8307c 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,6 @@ Homepage: http://projects.maartendamen.com/projects/houseagent Package: houseagent Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, rabbitmq-server, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling +Depends: ${misc:Depends}, ${python:Depends}, python-zeromq, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling Description: Home automation core framework. HouseAgent is a multi platform, open source home automation application. From fa57993bd818a9f80489a290556458c7b4367c20 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Sun, 6 Nov 2011 21:23:50 +1000 Subject: [PATCH 03/14] Corrected dependency on ZeroMQ. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 9d8307c..7c827cf 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,6 @@ Homepage: http://projects.maartendamen.com/projects/houseagent Package: houseagent Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, python-zeromq, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling +Depends: ${misc:Depends}, ${python:Depends}, python-pyzmq, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling Description: Home automation core framework. HouseAgent is a multi platform, open source home automation application. From 0efb44db26d0dd4b58cd3dcaf6be42357cdeddbf Mon Sep 17 00:00:00 2001 From: David Whyte Date: Sun, 6 Nov 2011 22:32:34 +1000 Subject: [PATCH 04/14] Added dependency on txZMQ. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 7c827cf..8c26adc 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,6 @@ Homepage: http://projects.maartendamen.com/projects/houseagent Package: houseagent Architecture: all -Depends: ${misc:Depends}, ${python:Depends}, python-pyzmq, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling +Depends: ${misc:Depends}, ${python:Depends}, python-pyzmq, python-twisted-web, python-mako, python-pyrrd, python-txamqp, twisted.scheduling, txzmq Description: Home automation core framework. HouseAgent is a multi platform, open source home automation application. From 9d107dabbe9e79fa17e14350bb90a135a3eeba9c Mon Sep 17 00:00:00 2001 From: David Whyte Date: Mon, 7 Nov 2011 10:31:50 +1000 Subject: [PATCH 05/14] Commit of latest changelog from latest build on PPA --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index eaf1673..59ef9f8 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +houseagent (0.01.3-0ubuntu1) lucid; urgency=low + + * Update to GIT revision 0efb44d. Remove dependency on RabbitMQ, add dependency on ZeroMQ. + + -- David Whyte Sun, 06 Nov 2011 23:11:11 +1000 + houseagent (0.01-0ubuntu2) lucid; urgency=low * Minor modifications of the packaging meta-data From e305d6073d4f01cc2f92e5d39fcdb28c9ba37a0a Mon Sep 17 00:00:00 2001 From: David Whyte Date: Mon, 7 Nov 2011 12:14:45 +1000 Subject: [PATCH 06/14] Created an upstart job for the monitoring of HouseAgent. --- HouseAgent.py | 2 ++ deploy/houseagent.conf | 15 +++++++++++++++ setup.py | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 deploy/houseagent.conf diff --git a/HouseAgent.py b/HouseAgent.py index 80f4d11..eead7f3 100644 --- a/HouseAgent.py +++ b/HouseAgent.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python + from houseagent.core.coordinator import Coordinator from houseagent.core.events import EventHandler from houseagent.core.web import Web diff --git a/deploy/houseagent.conf b/deploy/houseagent.conf new file mode 100644 index 0000000..a1b8f67 --- /dev/null +++ b/deploy/houseagent.conf @@ -0,0 +1,15 @@ +description "HouseAgent management daemon" +author "David Whyte" + +start on started network +stop on stopping network +stop on starting shutdown + +console output + +pre-start script + mkdir -p /usr/share/HouseAgent/logs || true +end script + +exec /usr/bin/HouseAgent.py +respawn \ No newline at end of file diff --git a/setup.py b/setup.py index 2ef8068..390bc70 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ def find_package_files(workingdir, subdir): packages = ['houseagent','houseagent.core', 'houseagent.plugins', 'houseagent.utils', 'houseagent.pages'], package_data = {'houseagent': template_files}, scripts = ['HouseAgent.py'], - data_files = [('/etc/HouseAgent', ['HouseAgent.conf', 'specs/amqp0-8.xml', 'houseagent.db'])], + data_files = [('/etc/HouseAgent', ['HouseAgent.conf', 'specs/amqp0-8.xml', 'houseagent.db']), ('/etc/init', ['deploy/houseagent.conf'])], ) From 6cf88457fc2b454f7a2e27d75b5d81fc8c954ce0 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Mon, 7 Nov 2011 20:39:33 +1000 Subject: [PATCH 07/14] Update to changelog for latest packages --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 59ef9f8..9bf1a83 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +houseagent (0.01.20111107-1217-0ubuntu1) lucid; urgency=low + + * Changed the revision numbering to better support development packages. + * Created an upstart job for monitoring and management of HouseAgent. + + -- David Whyte Mon, 07 Nov 2011 12:18:14 +1000 + houseagent (0.01.3-0ubuntu1) lucid; urgency=low * Update to GIT revision 0efb44d. Remove dependency on RabbitMQ, add dependency on ZeroMQ. From b2b5e69cc4b188260f42449452a27ed490c837b5 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Wed, 16 Nov 2011 22:08:46 +1000 Subject: [PATCH 08/14] Correction to paths for the plugins and templates directories. Add extra debug data when can't load plugin pages.py file --- houseagent/__init__.py | 9 ++++++--- houseagent/core/web.py | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/houseagent/__init__.py b/houseagent/__init__.py index b7f296d..579e6e7 100644 --- a/houseagent/__init__.py +++ b/houseagent/__init__.py @@ -17,8 +17,11 @@ # If the path doesn't exist, lets assume we are running in a dev environment # and just return the current working directory. if not os.path.exists(os.path.join(config_path, 'HouseAgent.conf')): - config_path = os.getcwd() + config_path = os.path.join(os.getcwd(), '..', 'HouseAgent') +if not os.path.exists(os.path.join(config_path, 'HouseAgent.conf')): + config_path = os.getcwd() + # init config instance conf = Config(os.path.join(config_path, 'HouseAgent.conf')) @@ -42,8 +45,8 @@ """ Template directory """ template_dir = os.path.join(os.path.dirname(__file__), 'templates') -""" Template plugin directory """ -template_plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins') +""" Plugin directory """ +plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins') """ Logging directory """ if os.name == 'nt': diff --git a/houseagent/core/web.py b/houseagent/core/web.py index 04d2b55..e6fe26f 100644 --- a/houseagent/core/web.py +++ b/houseagent/core/web.py @@ -28,7 +28,7 @@ def __init__(self, port, coordinator, eventengine, database): @param eventengine: an instance of the event engine in order to interact with it @param database: an instance of the database layer in order to interact with it ''' - self.port = port # web server 0listening port + self.port = port # web server listening port self.coordinator = coordinator self.eventengine = eventengine self.db = database @@ -97,11 +97,11 @@ def __init__(self, port, coordinator, eventengine, database): def load_pages(self, root): ''' This function dynamically loads pages from plugins. - A pages.py file with atleast the init_pages() function must exist in the + A pages.py file with at least the init_pages() function must exist in the plugins// folder. @return: an array of loaded modules ''' - plugin_dir = os.path.join(os.path.dirname(houseagent.__file__), "plugins") + plugin_dir = houseagent.plugin_dir plugin_dirs = os.listdir(plugin_dir) for dir in plugin_dirs: @@ -112,8 +112,9 @@ def load_pages(self, root): mod = imp.load_module("pages", file, pathname, description) mod.init_pages(root, self.coordinator, self.db) print "Loaded pages for plugin %s" % dir - except: - print "Warning cannot load pages module for %s, no pages.py file?" % dir + except Exception, e: + print e + print "Warning cannot load pages module for %s. Exception received when loading pages file was \'%s\'." % (dir, e) class Root(Resource): ''' From 0a29abbb932dd3ee6cacd454f7fe9400abbacb63 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 17 Nov 2011 21:45:54 +1000 Subject: [PATCH 09/14] Fix to plugin_dir, correction to upstart script --- debian/changelog | 6 ++++++ deploy/houseagent.conf | 6 +----- houseagent/templates/master.html | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9bf1a83..13c7524 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +houseagent (0.01.20111116-2215-0ubuntu1) lucid; urgency=low + + * Minor fixes and upstream changes. + + -- David Whyte Wed, 16 Nov 2011 22:16:15 +1000 + houseagent (0.01.20111107-1217-0ubuntu1) lucid; urgency=low * Changed the revision numbering to better support development packages. diff --git a/deploy/houseagent.conf b/deploy/houseagent.conf index a1b8f67..195a12e 100644 --- a/deploy/houseagent.conf +++ b/deploy/houseagent.conf @@ -7,9 +7,5 @@ stop on starting shutdown console output -pre-start script - mkdir -p /usr/share/HouseAgent/logs || true -end script - -exec /usr/bin/HouseAgent.py +exec python /usr/bin/HouseAgent.py respawn \ No newline at end of file diff --git a/houseagent/templates/master.html b/houseagent/templates/master.html index d548cbf..e3b8816 100644 --- a/houseagent/templates/master.html +++ b/houseagent/templates/master.html @@ -30,10 +30,10 @@ main_items.append(main_item) parse_config(os.path.join(houseagent.template_dir, "menu.xml")) -for filename in os.listdir(houseagent.template_plugin_dir): +for filename in os.listdir(houseagent.plugin_dir): if not os.path.isfile(filename): - if (os.path.exists(os.path.join(houseagent.template_plugin_dir, filename, "menu.xml"))): - parse_config(os.path.join(houseagent.template_plugin_dir, filename, "menu.xml")) + if (os.path.exists(os.path.join(houseagent.plugin_dir, filename, "menu.xml"))): + parse_config(os.path.join(houseagent.plugin_dir, filename, "menu.xml")) %> From 303e8038c4b4a82f23f86dc2e71c7a58f2a25ece Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 24 Nov 2011 22:25:28 +1000 Subject: [PATCH 10/14] Really minor tweak to config file --- HouseAgent.conf | 1 - 1 file changed, 1 deletion(-) diff --git a/HouseAgent.conf b/HouseAgent.conf index adabd28..c4acbbf 100644 --- a/HouseAgent.conf +++ b/HouseAgent.conf @@ -22,7 +22,6 @@ logsize=1024 logcount=5 logconsole=True dbpath= - runasservice=False # ----------------------------------------------------------------------------- From b330bea52ce1b011fa20517ef849959e9c4d4198 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 24 Nov 2011 22:26:00 +1000 Subject: [PATCH 11/14] Update to setup script to specify the location of the logs and db on linux --- setup.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/setup.py b/setup.py index 390bc70..624d0a0 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,26 @@ #!/usr/bin/env python from distutils.core import setup +import ConfigParser import os version = '0.01' +def update_file(filename, search_line, replace_line): + infile = file(filename) + oldlines = infile.readlines() + infile.close + + newlines = [] + for line in oldlines: + if search_line in line: + line = replace_line + newlines.append(line) + + outfile = file(filename, 'w') + outfile.writelines(newlines) + + def find_package_files(workingdir, subdir): currentDir = os.getcwd() # Go into the working directory @@ -40,5 +56,8 @@ def find_package_files(workingdir, subdir): data_files = [('/etc/HouseAgent', ['HouseAgent.conf', 'specs/amqp0-8.xml', 'houseagent.db']), ('/etc/init', ['deploy/houseagent.conf'])], ) +# For linux, specify the log and db paths +update_file('HouseAgent.conf', 'logpath=', 'logpath=/var/log/HouseAgent/') +update_file('HouseAgent.conf', 'dbpath=', 'dbpath=/etc/HouseAgent/houseagent.db') setup(**data) \ No newline at end of file From bfce7037dfa263f30df3fd0ea00539309bfae30d Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 24 Nov 2011 22:26:52 +1000 Subject: [PATCH 12/14] Rename of the plugin_dir variable again (was lost in merge of upstream). --- houseagent/__init__.py | 9 ++++----- houseagent/core/web.py | 4 ++-- houseagent/templates/master.html | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/houseagent/__init__.py b/houseagent/__init__.py index 49895c8..b1b2add 100644 --- a/houseagent/__init__.py +++ b/houseagent/__init__.py @@ -33,14 +33,14 @@ def config_file(): # OSX and Linux else: - config_file = os.path.join(os.sep, 'etc', 'HouseAgent.conf') + config_file = os.path.join(os.sep, 'etc', 'HouseAgent', 'HouseAgent.conf') if os.path.exists(config_file): return config_file elif os.path.exists(os.path.join(os.getcwd(), 'HouseAgent.conf')): return os.path.join(os.getcwd(), 'HouseAgent.conf') else: - raise ConfigFileNotFound("/etc/ or working directory.") + raise ConfigFileNotFound("/etc/HouseAgent/ or working directory.") config_file = config_file() @@ -51,8 +51,7 @@ def config_file(): template_dir = os.path.join(os.path.dirname(__file__), 'templates') """ Plugin directory """ - if hasattr(sys, 'frozen'): - template_plugin_dir = os.path.join(os.path.dirname(sys.executable), 'plugins') + plugin_dir = os.path.join(os.path.dirname(sys.executable), 'plugins') else: - template_plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins') + plugin_dir = os.path.join(os.path.dirname(__file__), 'plugins') diff --git a/houseagent/core/web.py b/houseagent/core/web.py index f853370..6b17e4e 100644 --- a/houseagent/core/web.py +++ b/houseagent/core/web.py @@ -125,8 +125,8 @@ def load_pages(self, root): mod = imp.load_module("pages", file, pathname, description) mod.init_pages(root, self.coordinator, self.db) self.log.debug("--> Loaded pages for plugin %s" % dir) - except: - self.log.warning("--> Warning cannot load pages module for %s, no pages.py file?" % dir) + except Exception, e: + self.log.warning("--> Warning cannot load pages module for %s, no pages.py file?: %s" % (dir, e)) class Root(Resource): ''' diff --git a/houseagent/templates/master.html b/houseagent/templates/master.html index 0a1f1c5..3715d2c 100644 --- a/houseagent/templates/master.html +++ b/houseagent/templates/master.html @@ -30,10 +30,10 @@ main_items.append(main_item) parse_config(os.path.join(houseagent.template_dir, "menu.xml")) -for filename in os.listdir(houseagent.template_plugin_dir): +for filename in os.listdir(houseagent.plugin_dir): if not os.path.isfile(filename): - if (os.path.exists(os.path.join(houseagent.template_plugin_dir, filename, "menu.xml"))): - parse_config(os.path.join(houseagent.template_plugin_dir, filename, "menu.xml")) + if (os.path.exists(os.path.join(houseagent.plugin_dir, filename, "menu.xml"))): + parse_config(os.path.join(houseagent.plugin_dir, filename, "menu.xml")) %> From dfdabd6e621f7f3384c336897db11a756f02c57a Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 24 Nov 2011 22:29:21 +1000 Subject: [PATCH 13/14] Removed some debug code. --- houseagent/core/web.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/houseagent/core/web.py b/houseagent/core/web.py index 6b17e4e..f853370 100644 --- a/houseagent/core/web.py +++ b/houseagent/core/web.py @@ -125,8 +125,8 @@ def load_pages(self, root): mod = imp.load_module("pages", file, pathname, description) mod.init_pages(root, self.coordinator, self.db) self.log.debug("--> Loaded pages for plugin %s" % dir) - except Exception, e: - self.log.warning("--> Warning cannot load pages module for %s, no pages.py file?: %s" % (dir, e)) + except: + self.log.warning("--> Warning cannot load pages module for %s, no pages.py file?" % dir) class Root(Resource): ''' From cc749520998afc6bda05921bce0fcd54333df595 Mon Sep 17 00:00:00 2001 From: David Whyte Date: Thu, 24 Nov 2011 22:51:14 +1000 Subject: [PATCH 14/14] Plugins need to be able to access the config_dir, not just the config file. --- houseagent/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/houseagent/__init__.py b/houseagent/__init__.py index b1b2add..7884f1f 100644 --- a/houseagent/__init__.py +++ b/houseagent/__init__.py @@ -17,8 +17,9 @@ def config_file(): # Windows if os.name == 'nt': - from win32com.shell import shellcon, shell - config_file = config_file = os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0), 'HouseAgent', 'HouseAgent.conf') + from win32com.shell import shellcon, shell + config_dir = os.path.join(shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0), 'HouseAgent') + config_file = os.path.join(config_dir, 'HouseAgent.conf') if hasattr(sys, 'frozen'): # Special case for binary Windows version @@ -27,22 +28,23 @@ def config_file(): return config_file elif os.path.exists(os.path.join(os.getcwd(), 'HouseAgent.conf')): # development - return os.path.join(os.getcwd(), 'HouseAgent.conf') + return os.getcwd(), os.path.join(os.getcwd(), 'HouseAgent.conf') else: raise ConfigFileNotFound("ProgramData or working directory.") # OSX and Linux else: - config_file = os.path.join(os.sep, 'etc', 'HouseAgent', 'HouseAgent.conf') + config_dir = os.path.join(os.sep, 'etc', 'HouseAgent') + config_file = os.path.join(config_dir, 'HouseAgent.conf') if os.path.exists(config_file): - return config_file + return config_dir, config_file elif os.path.exists(os.path.join(os.getcwd(), 'HouseAgent.conf')): - return os.path.join(os.getcwd(), 'HouseAgent.conf') + return os.getcwd(), os.path.join(os.getcwd(), 'HouseAgent.conf') else: raise ConfigFileNotFound("/etc/HouseAgent/ or working directory.") -config_file = config_file() +config_dir, config_file = config_file() """ Template directory """ if hasattr(sys, 'frozen'):