Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate to py3.5 #257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ yarn.lock


modules/ui/package-lock.json

.python-version
upload/*
*.bak
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dockerfile for development on a pc/mac
FROM python:2
FROM python:3.5

EXPOSE 5000

Expand All @@ -11,4 +11,4 @@ RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "run.py"]
CMD ["python", "run.py"]
142 changes: 71 additions & 71 deletions modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
import json
import pprint
import sys, os
from flask import Flask, render_template, redirect
from flask_socketio import SocketIO, emit
import logging
# Define the WSGI application object
from app_config import *
import pprint
from modules.core.db import get_db
@app.route('/')
def index():
return redirect('ui')
# Define the database object which is imported
# by modules and controllers
import modules.steps
import modules.config
import modules.logs
import modules.sensors
import modules.actor
import modules.notification
import modules.fermenter
from modules.addon.endpoints import initPlugins
import modules.ui
import modules.system
import modules.buzzer
import modules.stats
import modules.kettle
import modules.recipe_import
import modules.core.db_mirgrate
from app_config import cbpi
# Build the database:
# This will create the database file using SQLAlchemy
pp = pprint.PrettyPrinter(indent=6)
def init_db():
print "INIT DB"
with app.app_context():
db = get_db()
try:
with app.open_resource('../config/schema.sql', mode='r') as f:
db.cursor().executescript(f.read())
db.commit()
except Exception as e:
pass
init_db()
initPlugins()
cbpi.run_init()
cbpi.run_background_processes()
app.logger.info("##########################################")
app.logger.info("### STARTUP COMPLETE")
import json
import pprint
import sys, os
from flask import Flask, render_template, redirect
from flask_socketio import SocketIO, emit

import logging
# Define the WSGI application object

from modules.app_config import *
import pprint

from modules.core.db import get_db


@app.route('/')
def index():
return redirect('ui')


# Define the database object which is imported
# by modules and controllers


import modules.steps
import modules.config
import modules.logs
import modules.sensors
import modules.actor
import modules.notification
import modules.fermenter
from modules.addon.endpoints import initPlugins
import modules.ui
import modules.system
import modules.buzzer
import modules.stats
import modules.kettle
import modules.recipe_import
import modules.core.db_mirgrate

from .app_config import cbpi
# Build the database:
# This will create the database file using SQLAlchemy


pp = pprint.PrettyPrinter(indent=6)


def init_db():
print("INIT DB")
with app.app_context():
db = get_db()

try:
with app.open_resource('../config/schema.sql', mode='r') as f:
db.cursor().executescript(f.read())

db.commit()
except Exception as e:
pass

init_db()
initPlugins()
cbpi.run_init()

cbpi.run_background_processes()



app.logger.info("##########################################")
app.logger.info("### STARTUP COMPLETE")
app.logger.info("##########################################")
2 changes: 1 addition & 1 deletion modules/addon/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import endpoints
import modules.addon.endpoints
7 changes: 4 additions & 3 deletions modules/addon/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import requests
import yaml
import shutil
import imp

blueprint = Blueprint('addon', __name__)

Expand All @@ -24,7 +25,7 @@ def merge(source, destination):
:param destination:
:return:
"""
for key, value in source.items():
for key, value in list(source.items()):
if isinstance(value, dict):
# get node or create one
node = destination.setdefault(key, {})
Expand Down Expand Up @@ -115,7 +116,7 @@ def reload(name):
"""
try:
if name in cache["modules"]:
reload(cache["modules"][name])
imp.reload(cache["modules"][name])
cbpi.emit_message("REALOD OF PLUGIN %s SUCCESSFUL" % (name))
return ('', 204)
else:
Expand All @@ -134,7 +135,7 @@ def plugins():
"""
response = requests.get("https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml")
cbpi.cache["plugins"] = merge(yaml.load(response.text), cbpi.cache["plugins"])
for key, value in cbpi.cache["plugins"].iteritems():
for key, value in cbpi.cache["plugins"].items():
value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key))

return json.dumps(cbpi.cache["plugins"])
Expand Down
8 changes: 4 additions & 4 deletions modules/base_plugins/brew_steps/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def execute(self):
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
self.notify("Mash Step Completed!", "Starting the next step", timeout=None)
self.next()
next(self)


@cbpi.step
Expand Down Expand Up @@ -121,7 +121,7 @@ def execute(self):
self.start_timer(int(self.timer) * 60)

if self.is_timer_finished() == True:
self.next()
next(self)

@cbpi.step
class PumpStep(StepBase):
Expand Down Expand Up @@ -149,7 +149,7 @@ def execute(self):
self.start_timer(int(self.timer) * 60)

if self.is_timer_finished() == True:
self.next()
next(self)

@cbpi.step
class BoilStep(StepBase):
Expand Down Expand Up @@ -226,4 +226,4 @@ def execute(self):
# Check if timer finished and go to next step
if self.is_timer_finished() == True:
self.notify("Boil Step Completed!", "Starting the next step", timeout=None)
self.next()
next(self)
2 changes: 1 addition & 1 deletion modules/base_plugins/dummy_temp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DummyTempSensor(SensorActive):

@cbpi.action("My Custom Action")
def my_action(self):
print "HELLO WORLD"
print("HELLO WORLD")
pass

def get_unit(self):
Expand Down
13 changes: 6 additions & 7 deletions modules/base_plugins/gpio_actor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

GPIO.setmode(GPIO.BCM)
except Exception as e:
print e
print(e)
pass


Expand All @@ -25,11 +25,11 @@ def init(self):
GPIO.output(int(self.gpio), 0)

def on(self, power=0):
print "GPIO ON %s" % str(self.gpio)
print(("GPIO ON %s" % str(self.gpio)))
GPIO.output(int(self.gpio), 1)

def off(self):
print "GPIO OFF"
print("GPIO OFF")
GPIO.output(int(self.gpio), 0)

@cbpi.actor
Expand Down Expand Up @@ -67,7 +67,7 @@ def set_power(self, power):
self.p.ChangeDutyCycle(self.power)

def off(self):
print "GPIO OFF"
print("GPIO OFF")
self.p.stop()


Expand Down Expand Up @@ -98,10 +98,9 @@ def on(self, power=100):
:param power: int value between 0 - 100
:return:
'''
print "ON"
print("ON")

def off(self):
print "OFF"

print("OFF")


2 changes: 1 addition & 1 deletion modules/buzzer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from thread import start_new_thread
from _thread import start_new_thread
from modules import cbpi

try:
Expand Down
2 changes: 1 addition & 1 deletion modules/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def init_cache(cls):

with cls.api.app.app_context():
cls.api.cache[cls.cache_key] = {}
for key, value in cls.model.get_all().iteritems():
for key, value in cls.model.get_all().items():
cls.post_init_callback(value)
cls.api.cache[cls.cache_key][value.name] = value

Expand Down
2 changes: 1 addition & 1 deletion modules/core/baseview.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ def init_cache(cls):
cls.api.cache[cls.cache_key].append(value)
else:
cls.api.cache[cls.cache_key] = {}
for key, value in cls.model.get_all().iteritems():
for key, value in list(cls.model.get_all().items()):
cls.post_init_callback(value)
cls.api.cache[cls.cache_key][key] = value
2 changes: 1 addition & 1 deletion modules/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ControllerBase(object):

@staticmethod
def init_global():
print "GLOBAL CONTROLLER INIT"
print("GLOBAL CONTROLLER INIT")

def notify(self, headline, message, type="success", timeout=5000):
self.api.notify(headline, message, type, timeout)
Expand Down
20 changes: 10 additions & 10 deletions modules/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from functools import wraps, update_wrapper


from props import *
from modules.core.props import *

from hardware import *
from modules.core.hardware import *

import time
import uuid
Expand All @@ -28,7 +28,7 @@ class ActorAPI(object):
def init_actors(self):
self.app.logger.info("Init Actors")
t = self.cache.get("actor_types")
for key, value in t.iteritems():
for key, value in list(t.items()):
value.get("class").api = self
value.get("class").init_global()

Expand Down Expand Up @@ -89,7 +89,7 @@ def init_sensors(self):
self.app.logger.info("Init Sensors")

t = self.cache.get("sensor_types")
for key, value in t.iteritems():
for key, value in list(t.items()):
value.get("class").init_global()

for key in self.cache.get("sensors"):
Expand Down Expand Up @@ -292,7 +292,7 @@ def __parseProps(self, key, cls):
t = tmpObj.__getattribute__(m)
self.cache[key][name]["properties"].append({"name": m, "label": t.label, "type": "kettle", "configurable": t.configurable, "description": t.description})

for name, method in cls.__dict__.iteritems():
for name, method in list(cls.__dict__.items()):
if hasattr(method, "action"):
label = method.__getattribute__("label")
self.cache[key][cls.__name__]["actions"].append({"method": name, "label": label})
Expand All @@ -309,10 +309,10 @@ def actor(self, cls):
def actor2(self, description="", power=True, **options):

def decorator(f):
print f()
print f
print options
print description
print((f()))
print(f)
print(options)
print(description)
return f
return decorator

Expand Down Expand Up @@ -369,7 +369,7 @@ def step(self, cls):
t = tmpObj.__getattribute__(m)
self.cache[key][name]["properties"].append({"name": m, "label": t.label, "type": "kettle", "configurable": t.configurable, "description": t.description})

for name, method in cls.__dict__.iteritems():
for name, method in list(cls.__dict__.items()):
if hasattr(method, "action"):
label = method.__getattribute__("label")
self.cache[key][cls.__name__]["actions"].append({"method": name, "label": label})
Expand Down
2 changes: 1 addition & 1 deletion modules/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def insert(cls, **kwargs):
cur = get_db().cursor()


if cls.__priamry_key__ is not None and kwargs.has_key(cls.__priamry_key__):
if cls.__priamry_key__ is not None and cls.__priamry_key__ in kwargs:
query = "INSERT INTO %s (%s, %s) VALUES (?, %s)" % (
cls.__table_name__,
cls.__priamry_key__,
Expand Down
Loading