Skip to content

Commit

Permalink
Standardize on " instead of '. Move to f-strings where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
yombo committed Nov 2, 2018
1 parent 8a5bced commit 0de3bc8
Show file tree
Hide file tree
Showing 193 changed files with 16,849 additions and 16,789 deletions.
129 changes: 65 additions & 64 deletions yombo.tac
Expand Up @@ -36,7 +36,7 @@ def show_help():
"""Display the help menu when calling the tac file directly (a no-no)."""
print("This file shouldn't be called directly by users. Please use either:")
print("1) ybo - If installed by Yombo install scripts")
print("2) %s/yombo.sh" % os.path.dirname(os.path.abspath(__file__)))
print(f"2) {os.path.dirname(os.path.abspath(__file__))}/yombo.sh")
print("\n")


Expand All @@ -48,53 +48,53 @@ def get_arguments():
:return:
"""
defaults = {
'app_dir': os.path.dirname(os.path.abspath(__file__)),
'debug': False,
'debug_items': [],
'norestoreini': False,
'restoreini': False,
'working_dir': "%s/.yombo" % os.path.expanduser("~"),
"app_dir": os.path.dirname(os.path.abspath(__file__)),
"debug": False,
"debug_items": [],
"norestoreini": False,
"restoreini": False,
"working_dir": f"{os.path.expanduser('~')}/.yombo",
}

# Reads arguments from stdin.
if select.select([sys.stdin, ], [], [], 0.05)[0]:
args = shlex.split(sys.stdin.readline())
arguments = {k: True if v.startswith('-') else v
for k, v in zip(args, args[1:] + ["--"]) if k.startswith('-')}
arguments = {k: True if v.startswith("-") else v
for k, v in zip(args, args[1:] + ["--"]) if k.startswith("-")}
else:
arguments = {}

if any(key in arguments for key in ['-?', '-h', '-help', '--help', '--?']):
if any(key in arguments for key in ["-?", "-h", "-help", "--help", "--?"]):
show_help()
exit()
if '-w' in arguments:
defaults['working_dir'] = arguments['-w']
if not os.path.exists('%s' % os.path.dirname(defaults['working_dir'])):
raise Exception("Invalid working directory '%s', the parent '%s' must exist." %
(defaults['working_dir'], os.path.dirname(defaults['working_dir'])))

if '-a' in arguments:
defaults['app_dir'] = arguments['-a']
elif '--app_dir' in arguments:
defaults['app_dir'] = arguments['--app_dir']
if not os.path.exists('%s' % defaults['app_dir']):
raise Exception("Invalid app directory '%s', it doesn't exist." % defaults['app_dir'])

if '-d' in arguments:
defaults['debug'] = True
elif '--debug' in arguments:
defaults['debug'] = True
if defaults['debug'] is True:
if '--debug-items' in arguments:
defaults['debug_items'] = arguments['--debug-items'].split(',')
if "-w" in arguments:
defaults["working_dir"] = arguments["-w"]
if not os.path.exists(str(os.path.dirname(defaults["working_dir"]))):
raise Exception(f"Invalid working directory 'defaults['working_dir']', "
f"the parent '{os.path.dirname(defaults['working_dir'])}' must exist.")

if "-a" in arguments:
defaults["app_dir"] = arguments["-a"]
elif "--app_dir" in arguments:
defaults["app_dir"] = arguments["--app_dir"]
if not os.path.exists(defaults["app_dir"]):
raise Exception(f"Invalid app directory '{defaults['app_dir']}', it doesn't exist.")

if "-d" in arguments:
defaults["debug"] = True
elif "--debug" in arguments:
defaults["debug"] = True
if defaults["debug"] is True:
if "--debug-items" in arguments:
defaults["debug_items"] = arguments["--debug-items"].split(",")
else:
defaults['debug_items'] = ['*']
defaults["debug_items"] = ["*"]

if '--norestoreini' in arguments:
defaults['norestoreini'] = True
if "--norestoreini" in arguments:
defaults["norestoreini"] = True

if '--restoreini' in arguments:
defaults['restoreini'] = True
if "--restoreini" in arguments:
defaults["restoreini"] = True

return defaults

Expand All @@ -104,47 +104,47 @@ def start():
try:
arguments = get_arguments()
except Exception as e:
print("Error starting Yombo: %s" % e)
print(f"Error starting Yombo: {e}")
exit()

working_dir = arguments['working_dir'] # Typically the user's directory: ~/.yombo
#ensure that usr data directory exists
if not os.path.exists('%s/gpg' % working_dir):
os.makedirs('%s/gpg' % working_dir)
if not os.path.exists('%s/bak' % working_dir):
os.makedirs('%s/bak' % working_dir)
if not os.path.exists('%s/bak/yombo_ini' % working_dir):
os.makedirs('%s/bak/yombo_ini' % working_dir)
if not os.path.exists('%s/bak/db' % working_dir):
os.makedirs('%s/bak/db' % working_dir)
if not os.path.exists('%s/etc' % working_dir):
os.makedirs('%s/etc' % working_dir)
if not os.path.exists('%s/etc/gpg' % working_dir):
os.makedirs('%s/etc/gpg' % working_dir)
if not os.path.exists('%s/etc/certs' % working_dir):
os.makedirs('%s/etc/certs' % working_dir)
if not os.path.exists('%s/locale' % working_dir):
os.makedirs('%s/locale' % working_dir)
if not os.path.exists('%s/log' % working_dir):
os.makedirs('%s/log' % working_dir)
if not os.path.exists('%s/opt' % working_dir):
os.makedirs('%s/opt' % working_dir)
working_dir = arguments["working_dir"] # Typically the user"s directory: ~/.yombo
# ensure that usr data directory exists
if not os.path.exists(f"{working_dir}/gpg"):
os.makedirs(f"{working_dir}/gpg")
if not os.path.exists(f"{working_dir}/bak"):
os.makedirs(f"{working_dir}/bak")
if not os.path.exists(f"{working_dir}/bak/yombo_ini"):
os.makedirs(f"{working_dir}/bak/yombo_ini")
if not os.path.exists(f"{working_dir}/bak/db"):
os.makedirs(f"{working_dir}/bak/db")
if not os.path.exists(f"{working_dir}/etc"):
os.makedirs(f"{working_dir}/etc")
if not os.path.exists(f"{working_dir}/etc/gpg"):
os.makedirs(f"{working_dir}/etc/gpg")
if not os.path.exists(f"{working_dir}/etc/certs"):
os.makedirs(f"{working_dir}/etc/certs")
if not os.path.exists(f"{working_dir}/locale"):
os.makedirs(f"{working_dir}/locale")
if not os.path.exists(f"{working_dir}/log"):
os.makedirs(f"{working_dir}/log")
if not os.path.exists(f"{working_dir}/opt"):
os.makedirs(f"{working_dir}/opt")

# ensure only our user can read these directories. Allows a
# backup group to be assigned for backup purposes.
os.chmod('%s/etc' % working_dir, 0o700)
os.chmod('%s/etc/gpg' % working_dir, 0o700)
os.chmod('%s/etc/certs' % working_dir, 0o700)
os.chmod('%s/bak' % working_dir, 0o760)
os.chmod(f"{working_dir}/etc", 0o700)
os.chmod(f"{working_dir}/etc/gpg", 0o700)
os.chmod(f"{working_dir}/etc/certs", 0o700)
os.chmod(f"{working_dir}/bak", 0o760)

os.system('gpg-agent --homedir %s/etc/gpg/ --daemon > file 2>&1' % working_dir)
os.system(f"gpg-agent --homedir {working_dir}/etc/gpg/ --daemon > file 2>&1")

results = settings.init(arguments)
if results is False:
print("Error with loading yombo.ini. Quiting.")
exit(200)
from twisted.application import service as twisted_service
application = twisted_service.Application('yombo')
application = twisted_service.Application("yombo")

# Gateway service is responsible for actually running everything.
from yombo.core.gwservice import GWService
Expand All @@ -153,5 +153,6 @@ def start():
gwservice.start()
return application


if __name__ == "builtins":
application = start()
2 changes: 1 addition & 1 deletion yombo/__init__.py
Expand Up @@ -4,6 +4,6 @@
Yombo Gateway developers API documentation.
.. moduleauthor:: Mitch Schwenk <mitch-gw@yombo.net>
:copyright: Copyright 2012-2016 by Yombo.
:copyright: Copyright 2012-2018 by Yombo.
:license: See LICENSE file for details.
"""
162 changes: 81 additions & 81 deletions yombo/constants/__init__.py
Expand Up @@ -19,101 +19,101 @@
MAJOR_VERSION = 0
MINOR_VERSION = 22
PATCH_VERSION = 0
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
__short_version__ = f"{MAJOR_VERSION}.{MINOR_VERSION}"
__version__ = f"{__short_version__}.{PATCH_VERSION}"

REQUIRED_PYTHON_VER = (3, 5, 3)

# Yombo gateway version number
VERSION = __version__

# Days of the week
WEEKDAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']
WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]

# Measurement systems
MISC_UNIT_SYSTEM_METRIC = 'metric' # type: str
MISC_UNIT_SYSTEM_IMPERIAL = 'imperial' # type: str
MISC_UNIT_SYSTEM_METRIC = "metric" # type: str
MISC_UNIT_SYSTEM_IMPERIAL = "imperial" # type: str

# Temperature systems
TEMP_CELSIUS = '°C'
TEMP_FAHRENHEIT = '°F'
TEMP_CELSIUS = "°C"
TEMP_FAHRENHEIT = "°F"

# Misc Attributes

ATR_ICON = 'icon'
ATR_CODE = 'code'
ATR_ICON = "icon"
ATR_CODE = "code"

# #### STATUS ####
STATUS_ON = 'on'
STATUS_OFF = 'off'
STATUS_HOME = 'home'
STATUS_NOT_HOME = 'not_home'
STATUS_UNKNOWN = 'unknown'
STATUS_OPEN = 'open'
STATUS_OPENING = 'opening'
STATUS_CLOSED = 'closed'
STATUS_CLOSING = 'closing'
STATUS_PLAYING = 'playing'
STATUS_PAUSED = 'paused'
STATUS_IDLE = 'idle'
STATUS_STANDBY = 'standby'
STATUS_ALARM_DISARMED = 'disarmed'
STATUS_ALARM_ARMED_HOME = 'armed_home'
STATUS_ALARM_ARMED_AWAY = 'armed_away'
STATUS_ALARM_ARMED_NIGHT = 'armed_night'
STATUS_ALARM_ARMED_CUSTOM_BYPASS = 'armed_custom_bypass'
STATUS_ALARM_PENDING = 'pending'
STATUS_ALARM_ARMING = 'arming'
STATUS_ALARM_DISARMING = 'disarming'
STATUS_ALARM_TRIGGERED = 'triggered'
STATUS_LOCKED = 'locked'
STATUS_UNLOCKED = 'unlocked'
STATUS_UNAVAILABLE = 'unavailable'
STATUS_OK = 'ok'
STATUS_PROBLEM = 'problem'
STATUS_ON = "on"
STATUS_OFF = "off"
STATUS_HOME = "home"
STATUS_NOT_HOME = "not_home"
STATUS_UNKNOWN = "unknown"
STATUS_OPEN = "open"
STATUS_OPENING = "opening"
STATUS_CLOSED = "closed"
STATUS_CLOSING = "closing"
STATUS_PLAYING = "playing"
STATUS_PAUSED = "paused"
STATUS_IDLE = "idle"
STATUS_STANDBY = "standby"
STATUS_ALARM_DISARMED = "disarmed"
STATUS_ALARM_ARMED_HOME = "armed_home"
STATUS_ALARM_ARMED_AWAY = "armed_away"
STATUS_ALARM_ARMED_NIGHT = "armed_night"
STATUS_ALARM_ARMED_CUSTOM_BYPASS = "armed_custom_bypass"
STATUS_ALARM_PENDING = "pending"
STATUS_ALARM_ARMING = "arming"
STATUS_ALARM_DISARMING = "disarming"
STATUS_ALARM_TRIGGERED = "triggered"
STATUS_LOCKED = "locked"
STATUS_UNLOCKED = "unlocked"
STATUS_UNAVAILABLE = "unavailable"
STATUS_OK = "ok"
STATUS_PROBLEM = "problem"

# Length units
LENGTH_CENTIMETERS = 'cm' # type: str
LENGTH_METERS = 'm' # type: str
LENGTH_KILOMETERS = 'km' # type: str
LENGTH_CENTIMETERS = "cm" # type: str
LENGTH_METERS = "m" # type: str
LENGTH_KILOMETERS = "km" # type: str

LENGTH_INCHES = 'in' # type: str
LENGTH_FEET = 'ft' # type: str
LENGTH_YARD = 'yd' # type: str
LENGTH_MILES = 'mi' # type: str
LENGTH_INCHES = "in" # type: str
LENGTH_FEET = "ft" # type: str
LENGTH_YARD = "yd" # type: str
LENGTH_MILES = "mi" # type: str

# Volume units
VOLUME_LITERS = 'L' # type: str
VOLUME_MILLILITERS = 'mL' # type: str
VOLUME_LITERS = "L" # type: str
VOLUME_MILLILITERS = "mL" # type: str

VOLUME_GALLONS = 'gal' # type: str
VOLUME_FLUID_OUNCE = 'fl. oz.' # type: str
VOLUME_GALLONS = "gal" # type: str
VOLUME_FLUID_OUNCE = "fl. oz." # type: str

# Mass units
MASS_GRAMS = 'g' # type: str
MASS_KILOGRAMS = 'kg' # type: str
MASS_GRAMS = "g" # type: str
MASS_KILOGRAMS = "kg" # type: str

MASS_OUNCES = 'oz' # type: str
MASS_POUNDS = 'lb' # type: str
MASS_OUNCES = "oz" # type: str
MASS_POUNDS = "lb" # type: str

# UV Index units
UNIT_UV_INDEX = 'UV index' # type: str

URL_ROOT = '/'
URL_API = '/api/'
URL_API_STREAM = '/api/stream'
URL_API_CONFIG = '/api/config'
URL_API_DISCOVERY_INFO = '/api/discovery_info'
URL_API_STATES = '/api/states'
URL_API_STATES_ENTITY = '/api/states/{}'
URL_API_EVENTS = '/api/events'
URL_API_EVENTS_EVENT = '/api/events/{}'
URL_API_SERVICES = '/api/services'
URL_API_SERVICES_SERVICE = '/api/services/{}/{}'
URL_API_COMPONENTS = '/api/components'
URL_API_ERROR_LOG = '/api/error_log'
URL_API_LOG_OUT = '/api/log_out'
URL_API_TEMPLATE = '/api/template'
UNIT_UV_INDEX = "UV index" # type: str

URL_ROOT = "/"
URL_API = "/api/"
URL_API_STREAM = "/api/stream"
URL_API_CONFIG = "/api/config"
URL_API_DISCOVERY_INFO = "/api/discovery_info"
URL_API_STATES = "/api/states"
URL_API_STATES_ENTITY = "/api/states/{}"
URL_API_EVENTS = "/api/events"
URL_API_EVENTS_EVENT = "/api/events/{}"
URL_API_SERVICES = "/api/services"
URL_API_SERVICES_SERVICE = "/api/services/{}/{}"
URL_API_COMPONENTS = "/api/components"
URL_API_ERROR_LOG = "/api/error_log"
URL_API_LOG_OUT = "/api/log_out"
URL_API_TEMPLATE = "/api/template"

HTTP_OK = 200
HTTP_CREATED = 201
Expand All @@ -125,25 +125,25 @@
HTTP_UNPROCESSABLE_ENTITY = 422
HTTP_INTERNAL_SERVER_ERROR = 500

CONTENT_TYPE_JSON = 'application/json'
CONTENT_TYPE_MSGPACK = 'application/msgpack'
CONTENT_TYPE_MULTIPART = 'multipart/x-mixed-replace; boundary={}'
CONTENT_TYPE_TEXT_PLAIN = 'text/plain'
CONTENT_TYPE_JSON = "application/json"
CONTENT_TYPE_MSGPACK = "application/msgpack"
CONTENT_TYPE_MULTIPART = "multipart/x-mixed-replace; boundary={}"
CONTENT_TYPE_TEXT_PLAIN = "text/plain"

# The exit code to send to request a restart
RESTART_EXIT_CODE = 127
QUIT_ERROR_EXIT_CODE = 1
QUIT_EXIT_CODE = 0

# Session types
AUTH_TYPE_USER = 'user' # an actual user object
AUTH_TYPE_AUTHKEY = 'authkey'
AUTH_TYPE_WEBSESSION = 'websession'

ENERGY_NONE = 'none'
ENERGY_ELECTRIC = 'electric'
ENERGY_GAS = 'gas'
ENERGY_WATER = 'water'
ENERGY_NOISE = 'noise'
AUTH_TYPE_USER = "user" # an actual user object
AUTH_TYPE_AUTHKEY = "authkey"
AUTH_TYPE_WEBSESSION = "websession"

ENERGY_NONE = "none"
ENERGY_ELECTRIC = "electric"
ENERGY_GAS = "gas"
ENERGY_WATER = "water"
ENERGY_NOISE = "noise"

ENERGY_TYPES = (ENERGY_NONE, ENERGY_ELECTRIC, ENERGY_GAS, ENERGY_WATER, ENERGY_NOISE)

0 comments on commit 0de3bc8

Please sign in to comment.