From 284e77bfe5d4a68f021a311041cc4576b7be912a Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 28 Jun 2018 19:05:27 +0200 Subject: Make Flake (somewhat) happy --- reaktor/commands/caps | 18 +++++++++----- reaktor/commands/identify | 27 +++++++++++---------- reaktor/commands/licht_resolver | 53 ++++++++++++++++++++--------------------- reaktor/commands/taken | 4 ++-- reaktor/commands/version | 14 ++++++----- 5 files changed, 63 insertions(+), 53 deletions(-) (limited to 'reaktor/commands') diff --git a/reaktor/commands/caps b/reaktor/commands/caps index b5d6642..6f26540 100755 --- a/reaktor/commands/caps +++ b/reaktor/commands/caps @@ -2,12 +2,18 @@ import imp import os + def load_config(filename): - dirname = os.path.dirname(filename) - modname, ext = os.path.splitext(os.path.basename(filename)) - file, pathname, description = imp.find_module(modname, [ dirname ]) - return imp.load_module(modname, file, pathname, description) + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [dirname]) + return imp.load_module(modname, file, pathname, description) + config = load_config(os.environ['config_filename']) -print('Private: '+' '.join(filter(None,[ x.get('capname',None) for x in config.commands]))) -print('Public: '+' '.join(filter(None,[ x.get('capname',None) for x in config.public_commands]))) +print('Private: '+' '.join(filter( + None, [x.get('capname', None) for x in config.commands] +))) +print('Public: '+' '.join(filter( + None, [x.get('capname', None) for x in config.public_commands] +))) diff --git a/reaktor/commands/identify b/reaktor/commands/identify index c2fb2c5..9cb5726 100755 --- a/reaktor/commands/identify +++ b/reaktor/commands/identify @@ -1,22 +1,25 @@ #!/usr/bin/env python import imp -import os,sys +import os +import sys + def load_config(filename): - dirname = os.path.dirname(filename) - modname, ext = os.path.splitext(os.path.basename(filename)) - file, pathname, description = imp.find_module(modname, [ dirname ]) - return imp.load_module(modname, file, pathname, description) + dirname = os.path.dirname(filename) + modname, ext = os.path.splitext(os.path.basename(filename)) + file, pathname, description = imp.find_module(modname, [dirname]) + return imp.load_module(modname, file, pathname, description) + config = load_config(os.environ['config_filename']) with open(config.admin_file) as f: - for line in f: - nick,secret = line.split() - if sys.argv[1] == secret: - print("identified you as %s!"%nick) - with open(config.auth_file,'a+') as g: - g.write(os.environ['_prefix'] +"\n") - sys.exit(0) + for line in f: + nick, secret = line.split() + if sys.argv[1] == secret: + print("identified you as %s!" % nick) + with open(config.auth_file, 'a+') as g: + g.write(os.environ['_prefix'] + "\n") + sys.exit(0) print("unable to identify you, sorry") diff --git a/reaktor/commands/licht_resolver b/reaktor/commands/licht_resolver index 90d06c8..c86243e 100755 --- a/reaktor/commands/licht_resolver +++ b/reaktor/commands/licht_resolver @@ -1,37 +1,36 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- +import json +from os import environ as env +from struct import unpack map = { - 'shackspace': { - 'device': { - 0: 'Licht0, Zickenzone; Fenster', - 1: 'Licht1, Sofaecke; Fenster', - 2: 'Licht2, Zickenzone; Ghetto', - 3: 'Licht3, Sofaecke; Ghetto', - 4: 'Licht4, Richtung Getränkelager', - 5: 'Licht5, Porschekonsole', - 6: 'Licht6, Tomatenecke', - 7: 'Licht7, Ghetto', - 10: 'Hauptschalter' - }, - 'state': { - 0: 'aus', - 1: 'an', - 2: 'aus in T-10s' - }, - '->': 'ist' - } + 'shackspace': { + 'device': { + 0: 'Licht0, Zickenzone; Fenster', + 1: 'Licht1, Sofaecke; Fenster', + 2: 'Licht2, Zickenzone; Ghetto', + 3: 'Licht3, Sofaecke; Ghetto', + 4: 'Licht4, Richtung Getränkelager', + 5: 'Licht5, Porschekonsole', + 6: 'Licht6, Tomatenecke', + 7: 'Licht7, Ghetto', + 10: 'Hauptschalter' + }, + 'state': { + 0: 'aus', + 1: 'an', + 2: 'aus in T-10s' + }, + '->': 'ist' + } } -from struct import unpack -import json -from os import environ as env - location = "shackspace" map = map[location] -print (env["payload"]+"") -did, sid= unpack('BB', json.loads(env['payload'])) -device,state = map['device'][did], map['state'][sid] +print(env["payload"]+"") +did, sid = unpack('BB', json.loads(env['payload'])) +device, state = map['device'][did], map['state'][sid] arrow = map['->'] -print ' '.join([device, arrow, state]) +print(' '.join([device, arrow, state])) diff --git a/reaktor/commands/taken b/reaktor/commands/taken index b8beba6..e48fe5e 100755 --- a/reaktor/commands/taken +++ b/reaktor/commands/taken @@ -1,13 +1,13 @@ #!/bin/sh #!/bin/bash - + # domainavailable # Fast, domain name checker to use from the shell # Use globs for real fun: # domainavailable blah{1..3}.{com,net,org,co.uk} # Inspired by foca / giles: # http://gilesbowkett.blogspot.com/2009/02/simple-bash-domain-availability.html - + for d in $@; do if host "$d" | grep "NXDOMAIN" >&/dev/null; then diff --git a/reaktor/commands/version b/reaktor/commands/version index ff3c48f..d9c4c5d 100755 --- a/reaktor/commands/version +++ b/reaktor/commands/version @@ -1,21 +1,25 @@ #!/usr/bin/env python -url="https://pypi.python.org/pypi/Reaktor/json" -import requests import reaktor +import requests + +url = "https://pypi.python.org/pypi/Reaktor/json" + cur_version = reaktor.__version__ ret = requests.get(url).json() latest_version = ret["info"]["version"] + def vt(v): return tuple(map(int, (v.split(".")))) + try: rel = ret["releases"][cur_version][0]["upload_time"] -except: +except Exception: rel = "unknown release date" -print("{} - {}".format(cur_version,rel)) +print("{} - {}".format(cur_version, rel)) if vt(latest_version) > vt(cur_version): print(" newer release available: {}".format(latest_version)) elif vt(latest_version) < vt(cur_version): @@ -23,5 +27,3 @@ elif vt(latest_version) < vt(cur_version): else: # on the most current release pass - - -- cgit v1.2.3