The unified diff between revisions [50ac7d23..] and [0639490d..] is displayed below. It can also be downloaded as a raw diff.

#
#
# delete "config.py"
#
# add_file "config.py.example"
#  content [5eb3d3aab78438bcb82255b0ba9d8fc56735837e]
#
# patch "yowie.py"
#  from [bd82e0a47d455ab54b669b6e637b117fe11306d8]
#    to [ef2df1fc34094e09a0c1cb771c03dbd744a8c933]
#
============================================================
--- config.py.example	5eb3d3aab78438bcb82255b0ba9d8fc56735837e
+++ config.py.example	5eb3d3aab78438bcb82255b0ba9d8fc56735837e
@@ -0,0 +1,45 @@
+
+#
+# yowie : main configuration file
+#
+
+import os
+
+
+# paths
+install_path = '/Users/grahame/monotone/yowie/'
+plugin_path = os.path.join(install_path, 'plugins')
+# path to store the monotone db; this directory must exist
+db_path = os.path.join(install_path, 'db')
+# this directory will be created by monotone
+data_path = os.path.join(install_path, 'data')
+
+# monotone setup
+mtn = '/opt/monotone/bin/mtn'
+mtn_database = os.path.join(db_path, 'data.db')
+mtn_branch = 'net.angrygoats.yowie.data'
+mtn_key = 'yowie@glamdring.local'
+mtn_passphrase = 'fibblefoo'
+
+drivers = (
+    'basic_snmp',
+    'cisco_ios',
+)
+
+tables = (
+    'tables/ethernet_forwarding.csv',
+)
+tables = map(lambda x: os.path.join(install_path, x), tables)
+
+devices = {
+    'gringo.net.uwa.edu.au' : {
+        'driver' : 'basic_snmp',
+        'zone' : 'backbone',
+        'execute_on' : ('ssh', 'grahame@typhaon.ucs.uwa.edu.au'),
+    },
+#    'phlegethon.snap.uwa.edu.au' : {
+#        'driver' : 'basic_snmp',
+#        'zone' : 'snap',
+#        'execute_on' : ('ssh', 'phlegethon.snap.uwa.edu.au'),
+#    },
+}
============================================================
--- yowie.py	bd82e0a47d455ab54b669b6e637b117fe11306d8
+++ yowie.py	ef2df1fc34094e09a0c1cb771c03dbd744a8c933
@@ -1,5 +1,6 @@
 #!/usr/bin/env python2.4

+import socket
 import config
 import pipes
 import time
@@ -33,9 +34,11 @@ class TableIO:
             for row in csv.reader(open(self.filename)):
                 yield row

-    def write(self, rows, rowlen):
+    def write(self, header, rows):
         fd = open(self.filename, "w")
         writer = csv.writer(fd)
+        writer.writerow(header)
+        rowlen = len(header)
         for row in rows:
             if len(row) != rowlen:
                 raise Exception("Row has length %d (must be %d)" % (len(row), rowlen))
@@ -68,19 +71,44 @@ def simple_get_table(supported):
         return supported[args[0]](*args, **kwargs)
     return __get_table

-def monotone_commit():
-    def s(*args, **kwargs):
-        return os.system(*args, **kwargs) >> 8
-    os.chdir(config.data_path)
-    pq = pipes.quote
+pq = pipes.quote
+mtn_cmd = '%s --db=%s ' % (config.mtn,
+                            pq(config.mtn_database))
+mtn_branch_cmd = mtn_cmd + '--branch=%s ' % pq(config.mtn_branch)
+
+def s(*args, **kwargs):
+    return os.system(*args, **kwargs) >> 8
+
+def monotone_setup():
     if not os.access(config.mtn_database, os.R_OK):
-        rv = s(config.mtn + ' --db=%s db init' % pq(config.mtn_database))
+        log("monotone database %s not found, initialising it." % (config.mtn_database))
+        rv = s(mtn_cmd + 'db init')
         if rv != 0:
             raise Exception("Unable to initialise monotone database: %s" % config.mtn_database)
-    base_cmd = '%s --db=%s --branch=%s ' % (config.mtn,
-                                           pq(config.mtn_database),
-                                           pq(config.mtn_branch))
+    if not os.access(config.data_path, os.R_OK):
+        log("working directory not found; running monotone setup: %s" % config.data_path)
+        rv = s(mtn_branch_cmd + " setup %s" % pq(config.data_path))
+        if rv != 0:
+            raise Exception("Unable to initialise working directory: %s" % config.data_path)
+    os.chdir(config.data_path)
+    if not os.access("_MTN", os.R_OK):
+        raise Exception("Data path is not a monotone working directory: _MTN not found.")
+    open('_MTN/monotonerc', 'w').write('''
+function get_passphrase(keypair_id)
+    return "%s"
+end
+''' % config.mtn_passphrase)

+def monotone_commit():
+    os.chdir(config.data_path)
+    rv = s(mtn_cmd + " add .")
+    if rv != 0:
+        raise Exception("monotone add failed")
+    commit_message = "yowie.py on %s : automatic commit" % (socket.gethostname())
+    rv = s(mtn_branch_cmd + " -k %s --message=%s commit" % (pq(config.mtn_key), pq(commit_message)))
+    if rv != 0:
+        raise Exception("monotone commit failed")
+
 if __name__ == '__main__':
     def init_drivers():
         rv = {}
@@ -136,9 +164,10 @@ if __name__ == '__main__':
                 continue
             log("updating table %s on: %s" % (table, device))
             tio = TableIO(tables[table], get_filename(device, table))
-            rowlen = len(tables[table].columns)
-            tio.write(get_table(table, tio, devices[device]), rowlen)
+            header = tables[table].columns
+            tio.write(header, get_table(table, tio, devices[device]))

+    monotone_setup()
     drivers = init_drivers()
     devices = init_devices()
     tables = init_tables()