Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Change routing method (observable)
Browse files Browse the repository at this point in the history
  • Loading branch information
p3tecracknell committed May 28, 2013
1 parent 5a19c3e commit 4bc5d73
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 516 deletions.
119 changes: 119 additions & 0 deletions static/css/bootstrap-switch.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* ============================================================
* bootstrapSwitch v1.3 by Larentis Mattia @spiritualGuru
* http://www.larentis.eu/switch/
* ============================================================
* Licensed under the Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
* ============================================================ */
.has-switch {
border-radius: 30px;
display: inline-block;
cursor: pointer;
line-height: 1.231;
overflow: hidden;
position: relative;
text-align: left;
width: 80px;
-webkit-mask: url('../images/switch/mask.png') 0 0 no-repeat;
mask: url('../images/switch/mask.png') 0 0 no-repeat;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.has-switch.deactivate {
opacity: 0.5;
filter: alpha(opacity=50);
cursor: default !important;
}
.has-switch.deactivate label,
.has-switch.deactivate span {
cursor: default !important;
}
.has-switch > div {
width: 162%;
position: relative;
top: 0;
}
.has-switch > div.switch-animate {
-webkit-transition: left 0.25s ease-out;
-moz-transition: left 0.25s ease-out;
-o-transition: left 0.25s ease-out;
transition: left 0.25s ease-out;
-webkit-backface-visibility: hidden;
}
.has-switch > div.switch-off {
left: -63%;
}
.has-switch > div.switch-off label {
background-color: #7f8c9a;
border-color: #bdc3c7;
-webkit-box-shadow: -1px 0 0 rgba(255, 255, 255, 0.5);
-moz-box-shadow: -1px 0 0 rgba(255, 255, 255, 0.5);
box-shadow: -1px 0 0 rgba(255, 255, 255, 0.5);
}
.has-switch > div.switch-on {
left: 0%;
}
.has-switch > div.switch-on label {
background-color: #1abc9c;
}
.has-switch input[type=checkbox] {
display: none;
}
.has-switch span {
cursor: pointer;
font-size: 14.994px;
font-weight: 700;
float: left;
height: 29px;
line-height: 19px;
margin: 0;
padding-bottom: 6px;
padding-top: 5px;
position: relative;
text-align: center;
width: 50%;
z-index: 1;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
-webkit-transition: 0.25s ease-out;
-moz-transition: 0.25s ease-out;
-o-transition: 0.25s ease-out;
transition: 0.25s ease-out;
-webkit-backface-visibility: hidden;
}
.has-switch span.switch-left {
border-radius: 30px 0 0 30px;
background-color: #34495e;
color: #1abc9c;
border-left: 1px solid transparent;
}
.has-switch span.switch-right {
border-radius: 0 30px 30px 0;
background-color: #bdc3c7;
color: #ffffff;
text-indent: 7px;
}
.has-switch span.switch-right [class*="fui-"] {
text-indent: 0;
}
.has-switch label {
border: 4px solid #34495e;
border-radius: 50%;
float: left;
height: 21px;
margin: 0 -15px 0 -14px;
padding: 0;
position: relative;
vertical-align: middle;
width: 21px;
z-index: 100;
-webkit-transition: 0.25s ease-out;
-moz-transition: 0.25s ease-out;
-o-transition: 0.25s ease-out;
transition: 0.25s ease-out;
-webkit-backface-visibility: hidden;
}
24 changes: 22 additions & 2 deletions tellprox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
print "Sorry, requires Python 2.5, 2.6 or 2.7."
sys.exit(1)

import tellstick_api, json, bottle
import json, bottle

from api import API
from tellstick import TellstickAPI
from config import ConfigAPI
from bottle import template, redirect
from configobj import ConfigObj
from validate import Validator
Expand All @@ -15,8 +18,23 @@
CONFIG_PATH = 'config.ini'
CONFIG_SPEC = 'configspec.ini'

def fix_environ_middleware(app):
def fixed_app(environ, start_response):
print start_response
if environ.has_key('HTTP_X_FORWARDED_SERVER'):
if environ.has_key('REQUEST_URI') and environ['REQUEST_URI'] == '/devices':
b = environ['REQUEST_URI']
print environ
if environ.has_key('HTTP_X_FORWARDED_SERVER'):
print "hey"
#environ['wsgi.url_scheme'] = 'https'
#environ['HTTP_X_FORWARDED_HOST'] = 'example.com'
return app(environ, start_response)
return fixed_app

config = None
app = bottle.Bottle()
#app.wsgi = fix_environ_middleware(app.wsgi)

def main():
config = ConfigObj(CONFIG_PATH, configspec = CONFIG_SPEC)
Expand All @@ -27,7 +45,9 @@ def main():
print "Config file validation failed"
sys.exit(1)

tellstick_api.TellstickAPI(app, config)
api = API(app, config)
TellstickAPI(api, config)
ConfigAPI(api, config)

bottle.run(app,
host = config['host'],
Expand Down
18 changes: 18 additions & 0 deletions tellprox/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import bottle_helpers as bh

class API(object):
def __init__(self, app, config):
self.app = app
self.config = config
app.route('/<out_format:re:(?i)(xml|json)>/<ftype:path>/<func:path>',
method = ['GET', 'POST'],
callback = self.route_all)
self.callbacks = {}
def add_route(self, key, callback):
self.callbacks[key] = callback
def route_all(self, out_format, ftype, func):
if ftype in self.callbacks:
func = func.strip().lower()
resp = self.callbacks[ftype](func)
return bh.format_response(resp, out_format, self.config['pretty_print'])
bh.raise404()
23 changes: 23 additions & 0 deletions tellprox/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import bottle_helpers as bh

class ConfigAPI(object):
def __init__(self, api, config):
self.config = config
self.api = api
api.add_route('config', self.route)

def is_section(self, val):
if not isinstance(val, str):
print self.config[val].depth
return False#not isinstance(val, (str, unicode, list, tuple))

def route(self, func):
if (func == 'getall'):
return [{k:v} for k, v in self.config.iteritems()
if not self.is_section(k)]

elif (func == 'get'):
key = bh.get_string('key')
if key in self.config:
return self.config[key]
bh.raise404()
30 changes: 30 additions & 0 deletions tellprox/tasensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

class TASensor(object):
def __init__(self, config, rawsensor):
super(TASensor, self).__init__()
super(TASensor, self).__setattr__('id', str(rawsensor.id))
super(TASensor, self).__setattr__('raw', rawsensor)

# Create a config entry with default values if one doesn't exist
sensor_config = config['sensors']
if not self.id in sensor_config.keys():
sensor_config[self.id] = {
'ignore' : 0,
'name' : None
}

super(TASensor, self).__setattr__('config', config)
super(TASensor, self).__setattr__('snscfg', sensor_config[self.id])
super(TASensor, self).__setattr__('ignore', sensor_config[self.id]['ignore'])
super(TASensor, self).__setattr__('name', sensor_config[self.id]['name'])

def __setattr__(self, name, value):
if name == 'name':
self.snscfg['name'] = value
self.config.write()
elif name == 'ignore':
self.snscfg['ignore'] = int(value)
self.config.write()
else:
raise AttributeError(name)
super(TASensor, self).__setattr__(name, value)
Loading

0 comments on commit 4bc5d73

Please sign in to comment.