def __init__(self): self.logger = log.create_logger('camera') self.stop_flag = False paths.init_path_to_libs() import numpy as np import cv2 as cv2 self.np = np self.cv2 = cv2 signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) if len(sys.argv) > 2: self.user_token = sys.argv[1] mac = sys.argv[2] else: ul = user_login.UserLogin(self) ul.wait() self.user_token = ul.user_token mac = None self.image_extension = config.get_settings()["camera"]["img_ext"] self.image_quality = config.get_settings()["camera"]["img_qual"] self.hardware_resize = config.get_settings()["camera"]["hardware_resize"] self.min_loop_time = config.get_settings()["camera"]["min_loop_time"] self.search_cameras() self.http_client = http_client.HTTPClient(self, keep_connection_flag=True) if mac: self.http_client.mac = mac #we need to use MAC from client to ensure that it's not changed on camera restart self.main_loop()
def create_app(config_name): app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) bootstrap.init_app(app) mail.init_app(app) moment.init_app(app) db.init_app(app) login_manager.init_app(app) pagedown.init_app(app) from main import main as main_blueprint app.register_blueprint(main_blueprint) from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') from .gallery import gallery as gallery_blueprint app.register_blueprint(gallery_blueprint, url_prefix='/gallery') # attach routes and custom error pages here # addHandler to app import logging handler = create_logger(app.config['LOG_FOLDER'], level=logging.INFO) app.logger.addHandler(handler) return app
def __init__(self): config.Config.instance().set_app_pointer(self) self.logger = log.create_logger('', log.LOG_FILE) self.logger.info("Starting 3DPrinterOS client. Version %s_%s" % (version.version, version.build)) self.logger.info('Operating system: ' + platform.system() + ' ' + platform.release()) signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) self.detected_printers = [] self.network_printers = [] self.printer_interfaces = [] self.virtual_printer_enabled = False self.network_detect_flag = False self.stop_flag = False self.closing_status = [] self.rights_checker_waiter = rights.RightsCheckerWaiter(self) self.conveyor_kill_waiter = makerware_utils.ConveyorKillWaiter(self) self.network_connection_checker = http_client.NetworkConnectionChecker(self) self.init_interface() self.rights_checker_waiter.wait() self.conveyor_kill_waiter.wait() self.network_connection_checker.wait() self.updater = updater.Updater() self.user_login = user_login.UserLogin(self) self.user_login.wait() if self.user_login.user_token and hasattr(self.user_login, "profiles"): config.Config.instance().set_profiles(self.user_login.profiles) self.virtual_printer_enabled = config.get_settings()['virtual_printer']['enabled'] self.tray_controller = tray_controller.TrayController() self.camera_controller = camera_controller.CameraController(self.user_login.user_token,\ self.user_login.http_client.mac) self.cloud_sync_controller = cloud_sync_controller.CloudSyncController() else: self.logger.error("Can't retrieve user login or printer profiles. Exiting...") self.quit()
def __init__(self): self.logger = log.create_logger('cloud_sync', log.CLOUD_SYNC_LOG_FILE) signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) self.mswin = sys.platform.startswith('win') self.names_to_ignore = [os.path.basename(self.SENDED_PATH), os.path.basename(self.UNSENDABLE_PATH)] self.user_token = None self.error_code = None self.error_message = '' self.start()
def __init__(self): self.logger = log.create_logger('') signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) self.mswin = sys.platform.startswith('win') self.names_to_ignore = [os.path.basename(self.SENDED_PATH), os.path.basename(self.UNSENDABLE_PATH), '.DS_Store', 'Thumbs.db'] self.user_token = None self.error_code = None self.error_message = '' self.start()
def fork_new_process(value): try: pid = os.fork() except AttributeError: logger = create_logger() logger.error('Failed to fork subprocess') else: if pid > 0: pids.append(pid) else: function(value) sys.exit(0)
def print_time(undecorated_function): """Print time spent by decorated function :param undecorated_function: function to be decorated """ import functools import time from log import create_logger logger = create_logger(name=undecorated_function.__name__) @functools.wraps(undecorated_function) def decorated_function(*args, **kwargs): start_time = time.time() result = undecorated_function(*args, **kwargs) spent_time = time.time() - start_time logger.info('executed in {0:g} sec'.format(spent_time)) return result return decorated_function
def main(): import multiprocessing start_n = 100000000 n_procs = 2 logger = log.create_logger() logger.warning('N cpu = {0}'.format(multiprocessing.cpu_count())) multi_forks(function=fun, args=n_procs*[start_n]) sequencial(function=fun, args=n_procs*[start_n]) multi_processes(function=fun, args=n_procs*[start_n]) multi_threads(function=fun, args=n_procs*[start_n]) lst = [multiprocessing.Process(target=monitor), multiprocessing.Process(target=activity), multiprocessing.Process(target=disturbance)] map(lambda x: x.start(), lst) map(lambda x: x.join(), lst)
def __init__(self): self.logger = log.create_logger("app.camera") self.stop_flag = False paths.init_path_to_libs() import numpy as np import cv2 as cv2 self.np = np self.cv2 = cv2 signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) ul = user_login.UserLogin(self) ul.wait() self.user_token = ul.user_token self.image_extension = config.get_settings()["camera"]["img_ext"] self.image_quality = config.get_settings()["camera"]["img_qual"] self.hardware_resize = config.get_settings()["camera"]["hardware_resize"] self.min_loop_time = config.get_settings()["camera"]["min_loop_time"] self.search_cameras() self.http_client = http_client.HTTPClient(keep_connection_flag=True) self.main_loop()
def __init__(self): self.set_reboot_flag(False) self.logger = log.create_logger("app", log.LOG_FILE) self.logger.info("Starting 3DPrinterOS client. Version %s_%s" % (version.version, version.build)) self.logger.info('Operating system: ' + platform.system() + ' ' + platform.release()) self.time_stamp() signal.signal(signal.SIGINT, self.intercept_signal) signal.signal(signal.SIGTERM, self.intercept_signal) self.detected_printers = [] self.printer_interfaces = [] self.stop_flag = False self.updater = updater.Updater() self.rights_checker_and_waiter = rights.RightsCheckerAndWaiter(self) self.user_login = user_login.UserLogin(self) self.init_interface() self.rights_checker_and_waiter.wait() if self.user_login.wait_for_login(): config.Config.instance().set_profiles(self.user_login.profiles) if config.get_settings()["camera"]["enabled"]: self.camera_controller = camera_controller.CameraController() self.cloud_sync_controller = cloud_sync_controller.CloudSyncController()
def get_printers(self): logger = logging.getLogger(self.__class__.__name__) logger.info('Scanning for network printers...') printers = [] for profile in self.profiles: if 'network_detect' in profile: scanner = NetPrinterScan(profile) printers.extend(scanner.discovered_printers) logger.info('Discovered printers:\n' + str(printers)) return printers if __name__ == '__main__': class FakeApp: pass fa = FakeApp() fa.stop_flag = False import user_login import log log.create_logger("", None) user_login = user_login.UserLogin(fa) user_login.wait() if user_login.user_token and hasattr(user_login, "profiles"): config.Config.instance().set_profiles(user_login.profiles) detector = NetworkDetector() printers = detector.get_printers() print "Detected network printers: " print json.dumps(printers)
# -*- coding:utf-8 -*- __author__ = 'liming' import xmlrpclib from working_thread import ActivePool import threading from log import create_logger from db import Db_access from redis_proxy import redis_proxy import socket import time from utils.common import http_call logger = create_logger(__name__) def _cur_time(t_stamp=None): return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(t_stamp)) def get_rpc_list(): sql = 'select a.id as app_id, a.name, b.ip, b.user, b.password from app a inner join server b on a.server_id = b.id' _, c = Db_access().get(sql) return c def update_status(app_list): logger.debug('start to update app_list to cache') r = redis_proxy() for _app in app_list: r.set(_app['id'], _app['status'].lower()) _start = _app.get('start_time') start_time = _cur_time(_start) if _start is not None else 'unknown' r.set('start_time_' + str(_app['id']), start_time)
import os, sys, time from stat import * from multiprocessing.pool import ThreadPool from threading import Thread from db_manager import * import datetime import log #self.pool_predictors.apply_async() import numpy as np import pylab as pl PATH_LOG_FILE = './metadata_collector.log' log.init(PATH_LOG_FILE) logger = log.create_logger('Metatada_Collector') access_list = [] privacy_list = [] crea_mod_list = [] modification_list = [] size_list = [] group_files = {} user_files = {} class File_Inspector: def __init__(self): self.db_handler = DB_Manager(logger, database='file_metadata_db', user='******', host="localhost", password='******', port='5432') self.pool_manager = ThreadPool(processes=5)
import db import flask import logging import math import oauth2 as oauth import os import os.path import sqlalchemy as sa import subprocess import time import twitter import urllib import urlparse import warnings log = create_logger("mulchn") def create_app(): app = Flask(__name__) app.config.from_object('config') app.config.from_envvar('MULCHN_CONFIG', silent=True) app.config['ASSETS_UGLIFYJS_EXTRA_ARGS'] = '-m' app.config.setdefault('PAGINATION_NUM', 5) # db.configure_engine(os.environ.get("DATABASE_URL", app.config.get('DATABASE_URL'))) assets = Environment(app) css_slicklist = Bundle('css/slicklist.less', filters="less", output="css/slicklist.css")
else: self.logger.warning("Received strange answer: " + line.strip()) def is_ok(self, line): for ack in self.positive_acks: if line.startswith(ack): return True if 'closefile' in line: return True return self.ok_re.match(line) if __name__ == "__main__": import log log.create_logger("", "debug_log.txt") usb_info = {'COM': "COM18"} profile = { 'baudrate': [115200], "name": "Test", "alias": "Test", "no_DTR": False, "end_gcodes": [ "M104 S0", "M140 S0", "G28 X0 Y0", "M84" ] } with open("test_gcodes.gco", "r") as f: your_file_content = f.read()