Fix PEP257 issues

This commit is contained in:
Fabian Affolter committed 2016-03-09 11:15:04 +01:00
1 parent 986c9c55bf
commit f22a40c3e8
22 files changed
+95 -79

No files matched your search

+8 -11
View File
@@ -1,8 +1,5 @@
#!/usr/bin/env python3
"""
Generate an updated requirements_all.txt
"""
"""Generate an updated requirements_all.txt."""
import importlib
import os
import pkgutil
@@ -17,7 +14,7 @@ COMMENT_REQUIREMENTS = [
def explore_module(package, explore_children):
""" Explore the modules. """
"""Explore the modules."""
module = importlib.import_module(package)
found = []
@@ -35,7 +32,7 @@ def explore_module(package, explore_children):
def core_requirements():
""" Gather core requirements out of setup.py. """
"""Gather core requirements out of setup.py."""
with open('setup.py') as inp:
reqs_raw = re.search(
r'REQUIRES = \[(.*?)\]', inp.read(), re.S).group(1)
@@ -43,12 +40,12 @@ def core_requirements():
def comment_requirement(req):
""" Some requirements don't install on all systems. """
"""Some requirements don't install on all systems."""
return any(ign in req for ign in COMMENT_REQUIREMENTS)
def gather_modules():
""" Collect the information and construct the output. """
"""Collect the information and construct the output."""
reqs = {}
errors = []
@@ -95,19 +92,19 @@ def gather_modules():
def write_file(data):
""" Writes the modules to the requirements_all.txt. """
"""Write the modules to the requirements_all.txt."""
with open('requirements_all.txt', 'w+') as req_file:
req_file.write(data)
def validate_file(data):
""" Validates if requirements_all.txt is up to date. """
"""Validate if requirements_all.txt is up to date."""
with open('requirements_all.txt', 'r') as req_file:
return data == ''.join(req_file)
def main():
""" Main """
"""Main section of the script."""
if not os.path.isfile('requirements_all.txt'):
print('Run this from HA root dir')
return
+12 -11
View File
@@ -1,7 +1,8 @@
#! /usr/bin/python
"""
Query the Home Assistant API for available entities then print them and any
desired attributes to the screen.
Query the Home Assistant API for available entities.
Output is printed to stdout.
"""
import sys
@@ -17,19 +18,19 @@ import json
def main(password, askpass, attrs, address, port):
""" fetch Home Assistant api json page and post process """
# ask for password
"""Fetch Home Assistant API JSON page and post process."""
# Ask for password
if askpass:
password = getpass.getpass('Home Assistant API Password: ')
# fetch API result
# Fetch API result
url = mk_url(address, port, password)
response = urlopen(url).read()
if PYTHON == 3:
response = response.decode('utf-8')
data = json.loads(response)
# parse data
# Parse data
output = {'entity_id': []}
output.update([(attr, []) for attr in attrs])
for item in data:
@@ -37,18 +38,18 @@ def main(password, askpass, attrs, address, port):
for attr in attrs:
output[attr].append(item['attributes'].get(attr, ''))
# output data
# Output data
print_table(output, ['entity_id'] + attrs)
def print_table(data, columns):
""" format and print a table of data from a dictionary """
# get column lengths
"""Format and print a table of data from a dictionary."""
# Get column lengths
lengths = {}
for key, value in data.items():
lengths[key] = max([len(str(val)) for val in value] + [len(key)])
# print header
# Print header
for item in columns:
itemup = item.upper()
sys.stdout.write(itemup + ' ' * (lengths[item] - len(item) + 4))
@@ -63,7 +64,7 @@ def print_table(data, columns):
def mk_url(address, port, password):
""" construct the url call for the api states page """
"""Construct the URL call for the API states page."""
url = ''
if address.startswith('http://'):
url += address
+6 -7
View File
@@ -1,7 +1,5 @@
#!/usr/bin/env python3
"""
Downloads the latest Polymer v1 iconset version for materialdesignicons.com
"""
"""Download the latest Polymer v1 iconset for materialdesignicons.com."""
import hashlib
import os
import re
@@ -21,7 +19,7 @@ ICONSET_OUTPUT = os.path.join(OUTPUT_BASE, 'www_static', 'mdi.html')
def get_local_version():
""" Parse local version. """
"""Parse the local version."""
try:
with open(VERSION_OUTPUT) as inp:
for line in inp:
@@ -34,7 +32,7 @@ def get_local_version():
def get_remote_version():
""" Get current version and download link. """
"""Get current version and download link."""
gs_page = requests.get(GETTING_STARTED_URL).text
mdi_download = re.search(DOWNLOAD_LINK, gs_page)
@@ -50,12 +48,12 @@ def get_remote_version():
def clean_component(source):
""" Clean component. """
"""Clean component."""
return source[source.index(START_ICONSET):]
def write_component(version, source):
""" Write component. """
"""Write component."""
with open(ICONSET_OUTPUT, 'w') as outp:
print('Writing icons to', ICONSET_OUTPUT)
outp.write(source)
@@ -68,6 +66,7 @@ def write_component(version, source):
def main():
"""Main section of the script."""
# All scripts should have their current work dir set to project root
if os.path.basename(os.getcwd()) == 'script':
os.chdir('..')