Permalink
Browse files

Merge remote-tracking branch 'shanel/master' into test-merge

Conflicts:
	control_panel/_utils.py
	service_directory/_services.py
	service_directory/_utils.py
	service_directory/avahiclient.py
	service_directory/services.py
  • Loading branch information...
2 parents e04d43a + 915c94a commit 6e857803d2056cd296e7359c27fda996b0680a3d @Sitwon Sitwon committed Jul 23, 2012
@@ -323,7 +323,6 @@ def setup_iptables(args):
iptables = 0
if args.test:
logging.debug("Command that would be executed:\n%s", ' '.join(initialize_iptables))
- print str(initialize_iptables)
else:
iptables = subprocess.call(initialize_iptables)
return iptables
@@ -7,6 +7,7 @@
# captive_portal_test.py
+import flexmock # http://has207.github.com/flexmock
import unittest
import captive_portal
@@ -44,7 +44,7 @@ def _get_stash():
fobj = open(CACHEFILE,'r')
fstr = fobj.read()
fobj.close()
- if len(fstr) > 0:
+ if fstr:
try:
return json.loads()
except ValueError as ve:
@@ -129,7 +129,7 @@ def bring_out_your_dead(metrics):
# If the clients dict isn't populated, go through the dict of clients and
# associate the current time (in time_t format) with their packet count.
- if len(clients) < 1:
+ if not clients:
for c in metrics:
c['lastChanged'] = int(time.time())
clients[c['mac']] = c
@@ -167,7 +167,7 @@ def mop_up():
# If running this code as a separate process, main() gets called.
'''this is run if this is used as a script'''
def main(args):
- if len(args) > 1:
+ if args:
global CACHEFILE
global STASHTO
global MAXIDLESEC
View
@@ -1,5 +1,4 @@
-# -*- coding: utf-8 -*-
-# vim: set expandtab tabstop=4 shiftwidth=4 :
+from mako.exceptions import RichTraceback
def debug(message,level = '1'):
import os
@@ -26,4 +25,61 @@ def __init__(self):
self.services_store_dir = '/etc/avahi/inactive'
self.services_live_dir = '/etc/avahi/services'
+def execute_query(db, query, template=None):
+ """docstring for execute_query"""
+ connection = sqlite3.connect(db)
+ cursor = connection.cursor()
+ if template:
+ cursor.exectue(query % template)
+ else:
+ cursor.execute(query)
+ return connection, cursor
+def check_for_configured_interface(netconfdb, interface, channel, essid):
+ """docstring for check_for_configured_interface"""
+ warning = ""
+
+ # If a network interface is marked as configured in the database, pull
+ # its settings and insert them into the page rather than displaying the
+ # defaults.
+ query = "SELECT enabled, channel, essid FROM wireless WHERE mesh_interface=?;"
+ template = (interface, )
+ connection, cursor = execute_query(netconfdb, query, template)
+ result = cursor.fetchall()
+ if result and (result[0][0] == 'yes'):
+ channel = result[0][1]
+ essid = result[0][2]
+ warning = '<p>WARNING: This interface is already configured! Changing it now will break the local mesh! You can hit cancel now without changing anything!</p>'
+ connection.close()
+ return (channel, essid, warning)
+
+def set_confdbs(test):
+ if test:
+ # self.netconfdb = '/home/drwho/network.sqlite'
+ netconfdb = 'var/db/controlpanel/network.sqlite'
+ logging.debug("Location of netconfdb: %s", netconfdb)
+ # self.meshconfdb = '/home/drwho/mesh.sqlite'
+ meshconfdb = 'var/db/controlpanel/mesh.sqlite'
+ logging.debug("Location of meshconfdb: %s", meshconfdb)
+ else:
+ netconfdb = '/var/db/controlpanel/network.sqlite'
+ meshconfdb = '/var/db/controlpanel/mesh.sqlite'
+ return netconfdb, meshconfdb
+
+def set_wireless_db_entry(netconfdb, template):
+ """docstring for set_wireless_db_entry"""
+ # Commit the interface's configuration to the database.
+ connection = sqlite3.connect(netconfdb)
+ cursor = connection.cursor()
+ # Update the wireless table.
+ cursor.execute("UPDATE wireless SET enabled=?, channel=?, essid=?, mesh_interface=?, client_interface=? WHERE mesh_interface=?;", template)
+ connection.commit()
+ cursor.close()
+
+def output_error_data():
+ traceback = RichTraceback()
+ for filename, lineno, function, line in traceback.traceback:
+ print '\n'
+ print ('Error in file %s\n\tline %s\n\tfunction %s') % ((filename, lineno, function))
+ print ('Execution died on line %s\n') % (line)
+ print ('%s: %s') % ((str(traceback.error.__class__.__name__), traceback.error))
Oops, something went wrong.

0 comments on commit 6e85780

Please sign in to comment.