def write_login(login, password): logger = logging.getLogger('app.' + __name__) package_name = 'login_info.bin' # probably it shoud be read from config path = paths.current_settings_folder() try: result = pack_login_zip(package_name, path, login, password) except Exception as e: logger.warning('Login info writing error! ' + e.message) else: if result == True: logger.info('Login info was written and packed.') else: logger.warning("Login info wasn't written.") return True return False
import time import zipfile import logging import logging.handlers import traceback import shutil import paths import requests import http_client from os.path import join LOG_SNAPSHOT_LINES = 200 LOG_FILE = join(paths.current_settings_folder(), "3dprinteros_client.log") EXCEPTIONS_LOG_FILE = join(paths.current_settings_folder(), 'critical_errors.log') CLOUD_SYNC_LOG_FILE = join(paths.current_settings_folder(), '3dprinteros_cloudsync.log') LOG_SNAPSHOTS_DIR = join(paths.current_settings_folder(), 'log_snapshots') def create_logger(logger_name, log_file_name=None): logger = logging.getLogger(logger_name) logger.propagate = False logger.setLevel(logging.DEBUG) std_handler = logging.StreamHandler(stream=sys.stdout) std_handler.setLevel(logging.DEBUG) logger.addHandler(std_handler) if log_file_name: try: file_handler = logging.handlers.RotatingFileHandler(log_file_name, maxBytes=1024*1024*10, backupCount=10) file_handler.setFormatter(logging.Formatter('%(levelname)s\t%(asctime)s\t%(threadName)s/%(funcName)s\t%(message)s'))
import logging.handlers import traceback import shutil import platform import os.path import paths import requests import http_client import config import version import subprocess LOG_SNAPSHOT_LINES = 200 SETTINGS_FOLDER = paths.current_settings_folder() LOG_FILE = os.path.join(SETTINGS_FOLDER, "3dprinteros_client.log") EXCEPTIONS_LOG_FILE = os.path.join(SETTINGS_FOLDER, 'critical_errors.log') CLOUD_SYNC_LOG_FILE = os.path.join(SETTINGS_FOLDER, '3dprinteros_cloudsync.log') CAMERA_LOG_FILE = os.path.join(SETTINGS_FOLDER, "3dprinteros_camera.log") LOG_SNAPSHOTS_DIR = os.path.join(SETTINGS_FOLDER, 'log_snapshots') REPORT_FILE_NAME = 'problem_report.txt' REPORT_FILE_PATH = os.path.join(LOG_SNAPSHOTS_DIR, REPORT_FILE_NAME) LOG_FILE_SIZE = 1024*1024*10#(10MB) LOG_BACKUPS = 10 def create_logger(logger_name, log_file_name=None): logger = logging.getLogger(logger_name) logger.propagate = False logger.setLevel(logging.DEBUG)
class Config(Singleton): DEFAULT_SETTINGS_FILE = os.path.join(os.path.dirname(__file__), 'default_settings.json') USER_SETTINGS_FILE = os.path.join(paths.current_settings_folder(), 'user_settings.json') def __init__(self): self.init_settings() self.profiles = None self.app = None self.error_reports = collections.deque() def init_settings(self): initial_settings = self.load_settings(self.USER_SETTINGS_FILE, warnings=False) settings = self.load_settings(self.DEFAULT_SETTINGS_FILE) if initial_settings: settings = update_dict(initial_settings, settings) if settings != initial_settings: self.save_settings(settings, self.USER_SETTINGS_FILE) self.settings = settings def load_settings(self, settings_path, warnings=True): try: with open(settings_path) as settings_file: config = json.loads(settings_file.read()) except Exception as e: if warnings: print "Error reading config from %s: %s" % (settings_path, str(e)) else: return config def save_settings(self, settings, settings_path=None): if not settings_path: settings_path = self.USER_SETTINGS_FILE try: with open(settings_path, 'w') as settings_file: json_config = json.dumps(settings, sort_keys=True, indent=4, separators=(',', ': ')) settings_file.write(json_config) except Exception as e: print "Error writing config to %s: %s" % (settings_path, str(e)) else: self.settings = settings def restore_default_settings(self): if os.path.exists(self.USER_SETTINGS_FILE): try: os.remove(self.USER_SETTINGS_FILE) except Exception as e: return str(e) self.settings = self.load_settings(self.DEFAULT_SETTINGS_FILE) def set_profiles(self, profiles): self.profiles = profiles def set_app_pointer(self, app): self.app = app
import time import zipfile import logging import logging.handlers import traceback import shutil import paths import requests import http_client from os.path import join LOG_SNAPSHOT_LINES = 200 LOG_FILE = join(paths.current_settings_folder(), "3dprinteros_client.log") EXCEPTIONS_LOG_FILE = join(paths.current_settings_folder(), 'critical_errors.log') CLOUD_SYNC_LOG_FILE = join(paths.current_settings_folder(), '3dprinteros_cloudsync.log') LOG_SNAPSHOTS_DIR = join(paths.current_settings_folder(), 'log_snapshots') def create_logger(logger_name, log_file_name=None): logger = logging.getLogger(logger_name) logger.propagate = False logger.setLevel(logging.DEBUG) std_handler = logging.StreamHandler(stream=sys.stdout) std_handler.setLevel(logging.DEBUG) logger.addHandler(std_handler) if log_file_name: