| @@ -0,0 +1,27 @@ | |||||
| import requests | |||||
| from git import Repo, Git | |||||
| repo = Repo('./') | |||||
| branch = repo.active_branch | |||||
| print branch.name | |||||
| for remote in repo.remotes: | |||||
| remote.fetch() | |||||
| url = 'https://api.github.com/repos/manuel83/craftbeerpi3/releases' | |||||
| response = requests.get(url) | |||||
| result = {"branches":[], "releases": []} | |||||
| result["branches"].append({"name": "master"}) | |||||
| for branch in repo.branches: | |||||
| result["branches"].append({"name": branch.name}) | |||||
| for r in response.json(): | |||||
| result["releases"].append({"name": "tags/%s" % r.get("tag_name")}) | |||||
| print result | |||||
| @@ -19,7 +19,7 @@ class ActionView(FlaskView): | |||||
| 200: | 200: | ||||
| description: action invoked | description: action invoked | ||||
| """ | """ | ||||
| self.logger.info(self.cbpi.cache["actions"]) | |||||
| self.cbpi.cache["actions"][action]["function"](self.cbpi) | self.cbpi.cache["actions"][action]["function"](self.cbpi) | ||||
| return ('',204) | return ('',204) | ||||
| @@ -11,7 +11,7 @@ class Dummy(Actor): | |||||
| @cbpi.addon.actor.action("WOHOO") | @cbpi.addon.actor.action("WOHOO") | ||||
| def myaction(self): | def myaction(self): | ||||
| self.logger.debug("HALLO!!!") | |||||
| pass | |||||
| def on(self, power=100): | def on(self, power=100): | ||||
| ''' | ''' | ||||
| @@ -28,12 +28,10 @@ class Dummy(Actor): | |||||
| @cbpi.addon.kettle.controller() | @cbpi.addon.kettle.controller() | ||||
| class MyController(KettleController): | class MyController(KettleController): | ||||
| def __init__(self): | |||||
| self.logger = logging.getLogger(__name__) | |||||
| def run(self): | def run(self): | ||||
| while self.is_running(): | while self.is_running(): | ||||
| self.logger.debug("HALLO") | |||||
| self.sleep(1) | self.sleep(1) | ||||
| @cbpi.addon.fermenter.controller() | @cbpi.addon.fermenter.controller() | ||||
| @@ -50,10 +48,7 @@ class MyController2(FermenterController): | |||||
| def init(cbpi): | def init(cbpi): | ||||
| class MyBuzzer(Buzzer): | class MyBuzzer(Buzzer): | ||||
| def __init__(self): | |||||
| self.logger = logging.getLogger(__name__) | |||||
| def beep(self): | def beep(self): | ||||
| self.logger.info("BEEEEEEP") | |||||
| pass | |||||
| cbpi.buzzer = MyBuzzer() | cbpi.buzzer = MyBuzzer() | ||||
| @@ -21,6 +21,7 @@ class Dummy(Sensor): | |||||
| self.logger.info("INIT SENSOR") | self.logger.info("INIT SENSOR") | ||||
| def init(self): | def init(self): | ||||
| if self.api.get_config_parameter("unit","C") == "C": | if self.api.get_config_parameter("unit","C") == "C": | ||||
| self.unit = "°C" | self.unit = "°C" | ||||
| else: | else: | ||||
| @@ -28,7 +29,6 @@ class Dummy(Sensor): | |||||
| @cbpi.addon.sensor.action("WOHOO") | @cbpi.addon.sensor.action("WOHOO") | ||||
| def myaction(self): | def myaction(self): | ||||
| self.logger.info(self.text) | |||||
| self.logger.debug("SENSOR ACTION HALLO!!!") | self.logger.debug("SENSOR ACTION HALLO!!!") | ||||
| def execute(self): | def execute(self): | ||||
| @@ -41,8 +41,6 @@ class Dummy(Sensor): | |||||
| @cbpi.addon.core.action(key="clear", label="Clear all Logs") | @cbpi.addon.core.action(key="clear", label="Clear all Logs") | ||||
| def woohoo(cbpi): | def woohoo(cbpi): | ||||
| logger = logging.getLogger(__name__) | |||||
| logger.info("COOL") | |||||
| dir = "./logs" | dir = "./logs" | ||||
| test = os.listdir(dir) | test = os.listdir(dir) | ||||
| @@ -1,5 +1,3 @@ | |||||
| import logging | |||||
| from modules.core.basetypes import Step | from modules.core.basetypes import Step | ||||
| from modules.core.core import cbpi | from modules.core.core import cbpi | ||||
| from modules.core.proptypes import Property | from modules.core.proptypes import Property | ||||
| @@ -8,23 +6,20 @@ from modules.core.proptypes import Property | |||||
| @cbpi.addon.step.type("Dummy Step") | @cbpi.addon.step.type("Dummy Step") | ||||
| class Dummy(Step): | class Dummy(Step): | ||||
| def __init__(self): | |||||
| self.logger = logging.getLogger(__name__) | |||||
| @cbpi.addon.step.action("WOHOO") | @cbpi.addon.step.action("WOHOO") | ||||
| def myaction(self): | def myaction(self): | ||||
| self.stop_timer() | self.stop_timer() | ||||
| self.start_timer(10) | self.start_timer(10) | ||||
| self.logger.debug("HALLO") | |||||
| text = Property.Text(label="Text", configurable=True, description="WOHOOO") | text = Property.Text(label="Text", configurable=True, description="WOHOOO") | ||||
| time = Property.Text(label="Text", configurable=True, description="WOHOOO") | time = Property.Text(label="Text", configurable=True, description="WOHOOO") | ||||
| def execute(self): | def execute(self): | ||||
| self.logger.debug(self.text) | |||||
| #print self.text | |||||
| pass | pass | ||||
| def reset(self): | def reset(self): | ||||
| self.logger.info("RESET STEP!!!") | |||||
| self.stop_timer() | |||||
| self.stop_timer() | |||||
| @@ -164,7 +164,7 @@ class CoreAPI(BaseAPI): | |||||
| self.cbpi.cache["init"] = sorted(self.cbpi.cache["init"], key=lambda k: k['order']) | self.cbpi.cache["init"] = sorted(self.cbpi.cache["init"], key=lambda k: k['order']) | ||||
| for value in self.cbpi.cache.get("init"): | for value in self.cbpi.cache.get("init"): | ||||
| self.logger.debug(value) | |||||
| value["function"](self.cbpi) | value["function"](self.cbpi) | ||||
| def job(interval, method): | def job(interval, method): | ||||
| @@ -20,7 +20,7 @@ class Actor(Base): | |||||
| @classmethod | @classmethod | ||||
| def init_global(cls): | def init_global(cls): | ||||
| cls.__logger.info("GLOBAL INIT ACTOR") | |||||
| pass | pass | ||||
| def init(self): | def init(self): | ||||
| @@ -236,6 +236,7 @@ class Timer(object): | |||||
| class Step(Base, Timer): | class Step(Base, Timer): | ||||
| @classmethod | @classmethod | ||||
| def init_global(cls): | def init_global(cls): | ||||
| pass | pass | ||||
| @@ -76,7 +76,7 @@ class ActorCore(object): | |||||
| def init_one(self, id): | def init_one(self, id): | ||||
| try: | try: | ||||
| self.logger.info("INIT ONE ACTOR [%s]", id) | |||||
| actor = self.cbpi.cache["actors"][id] | actor = self.cbpi.cache["actors"][id] | ||||
| clazz = self.cbpi.cache[self.key].get(actor.type)["class"] | clazz = self.cbpi.cache[self.key].get(actor.type)["class"] | ||||
| cfg = actor.config.copy() | cfg = actor.config.copy() | ||||
| @@ -150,8 +150,7 @@ class ActorCore(object): | |||||
| job = self.cbpi._socketio.start_background_task(target=toggle, id=id, seconds=seconds) | job = self.cbpi._socketio.start_background_task(target=toggle, id=id, seconds=seconds) | ||||
| def get_state(self, actor_id): | def get_state(self, actor_id): | ||||
| self.logger.debug(actor_id) | |||||
| self.logger.debug(self.cbpi) | |||||
| pass | |||||
| class SensorCore(object): | class SensorCore(object): | ||||
| @@ -177,7 +176,7 @@ class SensorCore(object): | |||||
| cfg.update(dict(cbpi=self.cbpi, id=id)) | cfg.update(dict(cbpi=self.cbpi, id=id)) | ||||
| self.cbpi.cache["sensors"][id].instance = clazz(**cfg) | self.cbpi.cache["sensors"][id].instance = clazz(**cfg) | ||||
| self.cbpi.cache["sensors"][id].instance.init() | self.cbpi.cache["sensors"][id].instance.init() | ||||
| self.logger.debug(self.cbpi.cache["sensors"][id].instance) | |||||
| self.cbpi.emit("INIT_SENSOR", id=id) | self.cbpi.emit("INIT_SENSOR", id=id) | ||||
| def job(obj): | def job(obj): | ||||
| @@ -190,7 +189,7 @@ class SensorCore(object): | |||||
| self.logger.error(e) | self.logger.error(e) | ||||
| def stop_one(self, id): | def stop_one(self, id): | ||||
| self.logger.info("OBJ [%s]", self.cbpi.cache["sensors"][id]) | |||||
| self.cbpi.cache["sensors"][id].instance.stop() | self.cbpi.cache["sensors"][id].instance.stop() | ||||
| self.cbpi.emit("STOP_SENSOR", id=id) | self.cbpi.emit("STOP_SENSOR", id=id) | ||||
| @@ -201,8 +200,7 @@ class SensorCore(object): | |||||
| return None | return None | ||||
| def get_state(self, actor_id): | def get_state(self, actor_id): | ||||
| self.logger.info("Get state actor id [%s]", actor_id) | |||||
| self.logger.debug(self.cbpi) | |||||
| pass | |||||
| def write_log(self, id, value, prefix="sensor"): | def write_log(self, id, value, prefix="sensor"): | ||||
| filename = "./logs/%s_%s.log" % (prefix, str(id)) | filename = "./logs/%s_%s.log" % (prefix, str(id)) | ||||
| @@ -281,8 +279,6 @@ class CraftBeerPI(object): | |||||
| eventbus = {} | eventbus = {} | ||||
| def __init__(self): | def __init__(self): | ||||
| #FORMAT = '%(asctime)-15s - %(levelname)s - %(message)s' | |||||
| #logging.basicConfig(filename='./logs/app.log', level=logging.INFO, format=FORMAT) | |||||
| logging.config.dictConfig(yaml.load(open('./config/logger.yaml', 'r'))) | logging.config.dictConfig(yaml.load(open('./config/logger.yaml', 'r'))) | ||||
| self.logger = logging.getLogger(__name__) | self.logger = logging.getLogger(__name__) | ||||
| @@ -315,6 +311,7 @@ class CraftBeerPI(object): | |||||
| port = int(cbpi.get_config_parameter('port', '5000')) | port = int(cbpi.get_config_parameter('port', '5000')) | ||||
| except ValueError: | except ValueError: | ||||
| port = 5000 | port = 5000 | ||||
| print port | |||||
| self._socketio.run(self._app, host='0.0.0.0', port=port) | self._socketio.run(self._app, host='0.0.0.0', port=port) | ||||
| def beep(self): | def beep(self): | ||||
| @@ -331,7 +328,7 @@ class CraftBeerPI(object): | |||||
| self._socketio.emit(key, data, namespace='/brew') | self._socketio.emit(key, data, namespace='/brew') | ||||
| def __init_db(self, ): | def __init_db(self, ): | ||||
| self.logger.info("INIT DB") | |||||
| with self._app.app_context(): | with self._app.app_context(): | ||||
| db = self.get_db() | db = self.get_db() | ||||
| try: | try: | ||||
| @@ -390,7 +387,7 @@ class CraftBeerPI(object): | |||||
| def loadPlugins(self): | def loadPlugins(self): | ||||
| for filename in os.listdir("./modules/plugins"): | for filename in os.listdir("./modules/plugins"): | ||||
| self.logger.info("Loading plugin [%s]", filename) | |||||
| if os.path.isdir("./modules/plugins/" + filename) is False: | if os.path.isdir("./modules/plugins/" + filename) is False: | ||||
| continue | continue | ||||
| try: | try: | ||||
| @@ -19,7 +19,6 @@ def execute_file(curernt_version, data): | |||||
| conn.commit() | conn.commit() | ||||
| except sqlite3.OperationalError as err: | except sqlite3.OperationalError as err: | ||||
| cbpi._app.logger.info("EXCEPT") | |||||
| cbpi._app.logger.error(err) | cbpi._app.logger.error(err) | ||||
| @cbpi.addon.core.initializer(order=-9999) | @cbpi.addon.core.initializer(order=-9999) | ||||
| @@ -37,7 +36,7 @@ def init(cbpi): | |||||
| pass | pass | ||||
| result = [] | result = [] | ||||
| for filename in os.listdir("./update"): | for filename in os.listdir("./update"): | ||||
| cbpi._app.logger.info(filename) | |||||
| if filename.endswith(".sql"): | if filename.endswith(".sql"): | ||||
| d = {"version": int(filename[:filename.index('_')]), "file": filename} | d = {"version": int(filename[:filename.index('_')]), "file": filename} | ||||
| result.append(d) | result.append(d) | ||||
| @@ -18,6 +18,6 @@ def web(cbpi): | |||||
| def index(): | def index(): | ||||
| return s.send_static_file("index.html") | return s.send_static_file("index.html") | ||||
| logger.info("REGISTER") | |||||
| cbpi.addon.core.add_menu_link("JQuery View", "/web_view") | cbpi.addon.core.add_menu_link("JQuery View", "/web_view") | ||||
| cbpi._app.register_blueprint(s, url_prefix='/web_view') | cbpi._app.register_blueprint(s, url_prefix='/web_view') | ||||
| @@ -17,6 +17,6 @@ def web(cbpi): | |||||
| def index(): | def index(): | ||||
| return s.send_static_file("index.html") | return s.send_static_file("index.html") | ||||
| logger.info("REGISTER") | |||||
| cbpi.addon.core.add_menu_link("ReactJS View", "/webviewreact") | cbpi.addon.core.add_menu_link("ReactJS View", "/webviewreact") | ||||
| cbpi._app.register_blueprint(s, url_prefix='/webviewreact') | cbpi._app.register_blueprint(s, url_prefix='/webviewreact') | ||||
| @@ -162,7 +162,7 @@ class FermenterView(BaseView): | |||||
| def toggle(self, id): | def toggle(self, id): | ||||
| fermenter = cbpi.cache.get(self.cache_key)[id] | fermenter = cbpi.cache.get(self.cache_key)[id] | ||||
| try: | try: | ||||
| self.logger.info("Fermenter [%s] is in state [%s]",fermenter.id, fermenter.state) | |||||
| if fermenter.state is False: | if fermenter.state is False: | ||||
| # Start controller | # Start controller | ||||
| if fermenter.logic is not None: | if fermenter.logic is not None: | ||||
| @@ -188,7 +188,7 @@ class FermenterView(BaseView): | |||||
| cbpi.emit("FERMENTER_CONTROLLER_STOPPED", id=id) | cbpi.emit("FERMENTER_CONTROLLER_STOPPED", id=id) | ||||
| except Exception as e: | except Exception as e: | ||||
| self.logger.error(e) | |||||
| cbpi.notify("Toogle Fementer Controller failed", "Pleae check the %s configuration" % fermenter.name, | cbpi.notify("Toogle Fementer Controller failed", "Pleae check the %s configuration" % fermenter.name, | ||||
| type="danger", timeout=None) | type="danger", timeout=None) | ||||
| return ('', 500) | return ('', 500) | ||||
| @@ -10,7 +10,7 @@ class User(flask_login.UserMixin): | |||||
| @addon.core.initializer(order=0) | @addon.core.initializer(order=0) | ||||
| def log(cbpi): | def log(cbpi): | ||||
| logger = logging.getLogger(__name__) | |||||
| cbpi._login_manager = flask_login.LoginManager() | cbpi._login_manager = flask_login.LoginManager() | ||||
| cbpi._login_manager.init_app(cbpi._app) | cbpi._login_manager.init_app(cbpi._app) | ||||
| @@ -39,8 +39,8 @@ def log(cbpi): | |||||
| @cbpi._login_manager.user_loader | @cbpi._login_manager.user_loader | ||||
| def user_loader(user): | def user_loader(user): | ||||
| logger.debug(cbpi.get_config_parameter("password_security", "NO")) | |||||
| logger.debug(user) | |||||
| if cbpi.get_config_parameter("password_security", "NO") == "YES": | if cbpi.get_config_parameter("password_security", "NO") == "YES": | ||||
| if user != "craftbeerpi": | if user != "craftbeerpi": | ||||
| @@ -1,6 +1,7 @@ | |||||
| import flask_login | import flask_login | ||||
| import requests | |||||
| import yaml | import yaml | ||||
| from flask import json, url_for, Response | |||||
| from flask import json, url_for, Response, request | |||||
| from flask_classy import FlaskView, route | from flask_classy import FlaskView, route | ||||
| from flask_login import login_required, current_user | from flask_login import login_required, current_user | ||||
| from git import Repo, Git | from git import Repo, Git | ||||
| @@ -54,8 +55,15 @@ class SystemView(FlaskView): | |||||
| return ('', 204) | return ('', 204) | ||||
| @login_required | @login_required | ||||
| @route('/tags/<name>', methods=['GET']) | |||||
| def checkout_tag(self,name): | |||||
| @route('/checkout', methods=['POST']) | |||||
| def checkout_tag(self): | |||||
| data = request.json | |||||
| name = data.get("name") | |||||
| if name is None: | |||||
| return ('', 500) | |||||
| repo = Repo('./') | repo = Repo('./') | ||||
| repo.git.reset('--hard') | repo.git.reset('--hard') | ||||
| o = repo.remotes.origin | o = repo.remotes.origin | ||||
| @@ -65,9 +73,30 @@ class SystemView(FlaskView): | |||||
| cbpi.notify("Checkout successful", "Please restart the system") | cbpi.notify("Checkout successful", "Please restart the system") | ||||
| return ('', 204) | return ('', 204) | ||||
| @login_required | @login_required | ||||
| @route('/git/status', methods=['GET']) | @route('/git/status', methods=['GET']) | ||||
| def git_status(self): | def git_status(self): | ||||
| repo = Repo('./') | |||||
| o = repo.remotes.origin | |||||
| o.fetch() | |||||
| branch = repo.active_branch | |||||
| url = 'https://api.github.com/repos/manuel83/craftbeerpi3/releases' | |||||
| response = requests.get(url) | |||||
| result = {"current_branch": branch.name, "branches": [], "releases": []} | |||||
| result["branches"].append({"name": "master"}) | |||||
| for branch in repo.branches: | |||||
| result["branches"].append({"name": branch.name}) | |||||
| for r in response.json(): | |||||
| result["releases"].append({"name": "tags/%s" % r.get("tag_name")}) | |||||
| """ | """ | ||||
| Check for GIT status | Check for GIT status | ||||
| --- | --- | ||||
| @@ -77,28 +106,7 @@ class SystemView(FlaskView): | |||||
| 200: | 200: | ||||
| description: Git Status | description: Git Status | ||||
| """ | """ | ||||
| repo = Repo('./') | |||||
| o = repo.remotes.origin | |||||
| o.fetch() | |||||
| # Tags | |||||
| tags = [] | |||||
| for t in repo.tags: | |||||
| tags.append({"name": t.name, "commit": str(t.commit), "date": t.commit.committed_date, | |||||
| "committer": t.commit.committer.name, "message": t.commit.message}) | |||||
| try: | |||||
| branch_name = repo.active_branch.name | |||||
| # test1 | |||||
| except: | |||||
| branch_name = None | |||||
| changes = [] | |||||
| commits_behind = repo.iter_commits('master..origin/master') | |||||
| for c in list(commits_behind): | |||||
| changes.append({"committer": c.committer.name, "message": c.message}) | |||||
| return json.dumps({"tags": tags, "headcommit": str(repo.head.commit), "branchname": branch_name, | |||||
| "master": {"changes": changes}}) | |||||
| return json.dumps(result) | |||||
| @login_required | @login_required | ||||
| @route('/check_update', methods=['GET']) | @route('/check_update', methods=['GET']) | ||||
| @@ -2,10 +2,7 @@ from flask import Blueprint,render_template | |||||
| from modules.core.core import cbpi | from modules.core.core import cbpi | ||||
| import logging | |||||
| react = Blueprint('ui', __name__, template_folder='templates', static_folder='static') | react = Blueprint('ui', __name__, template_folder='templates', static_folder='static') | ||||
| __logger = logging.getLogger(__name__) | |||||
| @cbpi.addon.core.initializer(order=10) | @cbpi.addon.core.initializer(order=10) | ||||
| def init(cbpi): | def init(cbpi): | ||||
| @@ -14,13 +11,13 @@ def init(cbpi): | |||||
| @react.route('/', methods=["GET"]) | @react.route('/', methods=["GET"]) | ||||
| def index(): | def index(): | ||||
| # return react.send_static_file("index.html") | |||||
| #return react.send_static_file("index.html") | |||||
| js_files = [] | js_files = [] | ||||
| for key, value in cbpi.cache["js"].iteritems(): | for key, value in cbpi.cache["js"].iteritems(): | ||||
| js_files.append(value) | js_files.append(value) | ||||
| __logger.info(js_files) | |||||
| return render_template('index.html', js_files=js_files) | return render_template('index.html', js_files=js_files) | ||||