Python logger.error() Examples

The following are 30 code examples of logger.error(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module logger , or try the search function .
Example #1
Source File: encfstools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def path(self, path):
        """
        write crypted path to encfsctl stdin and read plain path from stdout
        if stdout is empty (most likly because there was an error) return crypt path
        """
        if self.string:
            assert isinstance(path, str), 'path is not str type: %s' % path
        else:
            assert isinstance(path, bytes), 'path is not bytes type: %s' % path
        if not 'p' in vars(self):
            self.startProcess()
        if not self.p.returncode is None:
            logger.warning('\'encfsctl decode\' process terminated. Restarting.', self)
            del self.p
            self.startProcess()
        self.p.stdin.write(path + self.newline)
        ret = self.p.stdout.readline()
        ret = ret.strip(self.newline)
        if ret:
            return ret
        return path

    #TODO: rename this, 'list' is corrupting sphinx doc 
Example #2
Source File: helpers.py    From appetite with Apache License 2.0 6 votes vote down vote up
def get_template_content(path):
    """Read either yml or json files and store them as dict"""
    template_dict = {}

    _filename, file_extension = os.path.splitext(path)
    file_extension = file_extension.replace('.', '')
    if file_extension in consts.TEMPLATING_EXTS:
        try:
            template_content = {}
            abs_path = os.path.abspath(os.path.expandvars(path))
            with open(abs_path, 'r') as stream:
                if file_extension in consts.JSON_EXTS:
                    template_content = json.load(stream) #nosec
                elif file_extension in consts.YMAL_EXTS:
                    template_content = yaml.safe_load(stream) #nosec
            template_dict.update(template_content)
        except Exception as e:
            logger.errorout("Error reading templating file",
                            file=path, error=e.message)
    else:
        logger.errorout("No templating file found",
                        file=path)

    return template_dict 
Example #3
Source File: helpers.py    From appetite with Apache License 2.0 6 votes vote down vote up
def run(cmd, working_dir=None, dry_run=False):
    """Runs local cmd command"""

    cmd_split = shlex.split(cmd) if isinstance(cmd, basestring) else cmd

    if dry_run:
        return " ".join(cmd_split), 0

    try:
        p = Popen(cmd_split, shell=False, stderr=STDOUT, stdout=PIPE, cwd=working_dir)

        communicate = p.communicate()

        return communicate[0].strip(), p.returncode
    except OSError as e:
        logger.errorout("Run OSError", error=e.message)
    except: # pylint: disable=bare-except
        logger.errorout("Run Error")

    return 
Example #4
Source File: helpers.py    From appetite with Apache License 2.0 6 votes vote down vote up
def get_config(config_file):
    """Read and get a config object

    Reads and checks an external configuration file
    """

    config = ConfigParser.ConfigParser(allow_no_value=True)

    config_fullpath = os.path.abspath(os.path.expandvars(config_file))

    # set xform for config otherwise text will be normalized to lowercase
    config.optionxform = str

    if not os.path.isfile(config_fullpath):
        logger.errorout("Commands config file does not exist",
                        path=config_file)
    try:
        if not config.read(config_fullpath):
            logger.errorout("Problem reading command config file")
    except Exception as e:
        logger.errorout('Error reading command config',
                        path=config_file,
                        error=e.message)

    return config 
Example #5
Source File: repo_manager.py    From appetite with Apache License 2.0 6 votes vote down vote up
def get_commit_log(self):
        """Get the current commit log
        """
        try:
            log_object = {}
            for key, value in COMMIT_KEYS.items():
                stdout, _rc = helpers.run(['git', 'log', '-1', '--pretty=\'%s\'' % value],
                                          self.paths['repo_path'],
                                          self.dryrun)

                output = "XXXXX" if self.dryrun else helpers.filter_content(stdout)
                if key in consts.RENAME_COMMIT_LOG_KEYS:
                    key = consts.RENAME_COMMIT_LOG_KEYS[key]
                log_object[key] = output

            log_object['project'] = self.project
            log_object['reponame'] = self.reponame

            return log_object
        except Exception as e:
            logger.errorout("get_commit_log", error="Problem getting commit log",
                            error_msg=e.message, track=self.track) 
Example #6
Source File: deploy.py    From gimel with MIT License 6 votes vote down vote up
def preflight_checks():
    logger.info('checking aws credentials and region')
    if region() is None:
        logger.error('Region is not set up. please run aws configure')
        return False
    try:
        check_aws_credentials()
    except AttributeError:
        logger.error('AWS credentials not found. please run aws configure')
        return False
    logger.info('testing redis')
    try:
        _redis().ping()
    except redis.exceptions.ConnectionError:
        logger.error('Redis ping failed. Please run gimel configure')
        return False
    return True 
Example #7
Source File: dlfuncs.py    From PyInstaLive with MIT License 6 votes vote down vote up
def get_broadcasts_info():
    try:
        user_id = get_user_id()
        if user_id:
            broadcasts = pil.ig_api.user_story_feed(user_id)
            pil.livestream_obj = broadcasts.get('broadcast')
            pil.replays_obj = broadcasts.get('post_live_item', {}).get('broadcasts', [])
            return True
        else:
            return False
    except ClientThrottledError:
        logger.error('Could not check because you are making too many requests at this time.')
        return False
    except Exception as e:
        logger.error('Could not finish checking: {:s}'.format(str(e)))
        if "timed out" in str(e):
            logger.error('The connection timed out, check your internet connection.')
        if "login_required" in str(e):
            logger.error('Login cookie was loaded but user is not actually logged in. Delete the cookie file and try '
                         'again.')
        return False
    except KeyboardInterrupt:
        logger.binfo('Aborted checking for livestreams and replays, exiting.')
        return False 
Example #8
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def makeDirs(self, path):
        """
        Wrapper for :py:func:`tools.makeDirs()`. Create directories ``path``
        recursive and return success. If not successful send error-message to
        log.

        Args:
            path (str): fullpath to directories that should be created

        Returns:
            bool:       ``True`` if successful
        """
        if not tools.makeDirs(path):
            logger.error("Can't create folder: %s" % path, self)
            self.setTakeSnapshotMessage(1, _('Can\'t create folder: %s') % path)
            time.sleep(2) #max 1 backup / second
            return False
        return True 
Example #9
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def displayName(self):
        """
        Combination of displayID, name and error indicator (if any)

        Returns:
            str:    name
        """
        ret = self.displayID
        name = self.name

        if name:
            ret += ' - {}'.format(name)

        if self.failed:
            ret += ' ({})'.format(_('WITH ERRORS !'))
        return ret 
Example #10
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def setLog(self, log):
        """
        Write log to "takesnapshot.log.bz2"

        Args:
            log: full snapshot log
        """
        if isinstance(log, str):
            log = log.encode('utf-8', 'replace')
        logFile = self.path(self.LOG)
        try:
            with bz2.BZ2File(logFile, 'wb') as f:
                f.write(log)
        except Exception as e:
            logger.error('Failed to write log into compressed file {}: {}'.format(
                         logFile, str(e)),
                         self) 
Example #11
Source File: music.py    From MusicBox with MIT License 6 votes vote down vote up
def start():
    app = QApplication(sys.argv)

    # 将Qt事件循环写到asyncio事件循环里。
    # QEventLoop不是Qt原生事件循环,
    # 是被asyncio重写的事件循环。
    eventLoop = QEventLoop(app)
    asyncio.set_event_loop(eventLoop)

    try:
        main = Window()

        main.show()
        # 当前音乐的显示信息。
        # 因为需要布局之后重新绘制的宽高。
        # 这个宽高会在show之后才会改变。
        # 需要获取宽,高并嵌入到父窗口里。
        main.playWidgets.currentMusic.resize(main.navigation.width(), 64)
        
        with eventLoop:
            eventLoop.run_forever()

        sys.exit(0)
    except:
        logger.error("got some error", exc_info=True) 
Example #12
Source File: tools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def makeDirs(path):
    """
    Create directories ``path`` recursive and return success.

    Args:
        path (str): fullpath to directories that should be created

    Returns:
        bool:       ``True`` if successful
    """
    path = path.rstrip(os.sep)
    if not path:
        return False

    if os.path.isdir(path):
        return True
    else:
        try:
            os.makedirs(path)
        except Exception as e:
            logger.error("Failed to make dirs '%s': %s"
                         %(path, str(e)), traceDepth = 1)
    return os.path.isdir(path) 
Example #13
Source File: password_ipc.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def isFifo(self):
        """
        make sure file is still a FIFO and has correct permissions
        """
        try:
            s = os.stat(self.fifo)
        except OSError:
            return False
        if not s.st_uid == os.getuid():
            logger.error('%s is not owned by user' % self.fifo, self)
            return False
        mode = s.st_mode
        if not stat.S_ISFIFO(mode):
            logger.error('%s is not a FIFO' % self.fifo, self)
            return False
        forbidden_perm = stat.S_IXUSR + stat.S_IRWXG + stat.S_IRWXO
        if mode & forbidden_perm > 0:
            logger.error('%s has wrong permissions' % self.fifo, self)
            return False
        return True 
Example #14
Source File: password.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, cfg = None, *args, **kwargs):
        self.config = cfg
        if self.config is None:
            self.config = config.Config()
        cachePath = self.config.passwordCacheFolder()
        if not tools.mkdir(cachePath, 0o700):
            msg = 'Failed to create secure Password_Cache folder'
            logger.error(msg, self)
            raise PermissionError(msg)
        pid = self.config.passwordCachePid()
        super(Password_Cache, self).__init__(pid, umask = 0o077, *args, **kwargs)
        self.dbKeyring = {}
        self.dbUsr = {}
        self.fifo = password_ipc.FIFO(self.config.passwordCacheFifo())

        self.keyringSupported = tools.keyringSupported() 
Example #15
Source File: backintime.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def benchmarkCipher(args):
    """
    Command for transferring a file with scp to remote host with all
    available ciphers and print its speed and time.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0
    """
    setQuiet(args)
    printHeader()
    cfg = getConfig(args)
    if cfg.snapshotsMode() in ('ssh', 'ssh_encfs'):
        ssh = sshtools.SSH(cfg)
        ssh.benchmarkCipher(args.FILE_SIZE)
        sys.exit(RETURN_OK)
    else:
        logger.error("SSH is not configured for profile '%s'!" % cfg.profileName())
        sys.exit(RETURN_ERR) 
Example #16
Source File: backintime.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def lastSnapshot(args):
    """
    Command for printing the very last snapshot in current profile.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0
    """
    force_stdout = setQuiet(args)
    cfg = getConfig(args)
    _mount(cfg)
    sid = snapshots.lastSnapshot(cfg)
    if sid:
        if args.quiet:
            msg = '{}'
        else:
            msg = 'SnapshotID: {}'
        print(msg.format(sid), file=force_stdout)
    else:
        logger.error("There are no snapshots in '%s'" % cfg.profileName())
    _umount(cfg)
    sys.exit(RETURN_OK) 
Example #17
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def makeDirs(self, *path):
        """
        Create snapshot directory

        Args:
            *path (str):    one or more folder/files to join at the end
                            of the path

        Returns:
            bool:           ``True`` if successful
        """
        if not os.path.isdir(self.config.snapshotsFullPath(self.profileID)):
            logger.error('Snapshots path {} doesn\'t exist. Unable to make dirs for snapshot ID {}'.format(
                         self.config.snapshotsFullPath(self.profileID), self.sid),
                         self)
            return False

        return tools.makeDirs(self.pathBackup(*path)) 
Example #18
Source File: pluginmanager.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def load(self, snapshots = None, cfg = None, force = False):
        if self.loaded and not force:
            return

        if snapshots is None:
            import snapshots as snapshots_
            snapshots = snapshots_.Snapshots(cfg)

        self.loaded = True
        self.plugins = []
        self.hasGuiPlugins = False

        loadedPlugins = []
        for path in ('plugins', 'common/plugins', 'qt/plugins'):
            fullPath = tools.backintimePath(path)
            if os.path.isdir(fullPath):
                logger.debug('Register plugin path %s' %fullPath, self)
                tools.registerBackintimePath(path)
                for f in os.listdir(fullPath):
                    if f not in loadedPlugins and f.endswith('.py') and not f.startswith('__'):
                        try:
                            module = __import__(f[: -3])
                            module_dict = module.__dict__

                            for key, value in list(module_dict.items()):
                                if key.startswith('__'):
                                    continue

                                if type(value) is type:
                                    if issubclass(value, Plugin):
                                        plugin = value()
                                        if plugin.init(snapshots):
                                            logger.debug('Add plugin %s' %f, self)
                                            if plugin.isGui():
                                                self.hasGuiPlugins = True
                                                self.plugins.insert(0, plugin)
                                            else:
                                                self.plugins.append(plugin)
                            loadedPlugins.append(f)
                        except BaseException as e:
                            logger.error('Failed to load plugin %s: %s' %(f, str(e)), self) 
Example #19
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def snapshotsList(args):
    """
    Command for printing a list of all snapshots in current profile.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0
    """
    force_stdout = setQuiet(args)
    cfg = getConfig(args)
    _mount(cfg)

    if args.quiet:
        msg = '{}'
    else:
        msg = 'SnapshotID: {}'
    no_sids = True
    #use snapshots.listSnapshots instead of iterSnapshots because of sorting
    for sid in snapshots.listSnapshots(cfg, reverse = False):
        print(msg.format(sid), file=force_stdout)
        no_sids = False
    if no_sids:
        logger.error("There are no snapshots in '%s'" % cfg.profileName())
    if not args.keep_mount:
        _umount(cfg)
    sys.exit(RETURN_OK) 
Example #20
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def smartRemove(args):
    """
    Command for running Smart-Remove from Terminal.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0 if okay
                        2 if Smart-Remove is not configured
    """
    setQuiet(args)
    printHeader()
    cfg = getConfig(args)
    sn = snapshots.Snapshots(cfg)

    enabled, keep_all, keep_one_per_day, keep_one_per_week, keep_one_per_month = cfg.smartRemove()
    if enabled:
        _mount(cfg)
        del_snapshots = sn.smartRemoveList(datetime.today(),
                                           keep_all,
                                           keep_one_per_day,
                                           keep_one_per_week,
                                           keep_one_per_month)
        logger.info('Smart Remove will remove {} snapshots'.format(len(del_snapshots)))
        sn.smartRemove(del_snapshots, log = logger.info)
        _umount(cfg)
        sys.exit(RETURN_OK)
    else:
        logger.error('Smart Remove is not configured.')
        sys.exit(RETURN_NO_CFG) 
Example #21
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def decode(args):
    """
    Command for decoding paths given paths with 'encfsctl'.
    Will listen on stdin if no path was given.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0
    """
    force_stdout = setQuiet(args)
    cfg = getConfig(args)
    if cfg.snapshotsMode() not in ('local_encfs', 'ssh_encfs'):
        logger.error("Profile '%s' is not encrypted." % cfg.profileName())
        sys.exit(RETURN_ERR)
    _mount(cfg)
    d = encfstools.Decode(cfg)
    if not args.PATH:
        while True:
            try:
                path = input()
            except EOFError:
                break
            if not path:
                break
            print(d.path(path), file = force_stdout)
    else:
        print('\n'.join(d.list(args.PATH)), file = force_stdout)
    d.close()
    _umount(cfg)
    sys.exit(RETURN_OK) 
Example #22
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def lastSnapshotPath(args):
    """
    Command for printing the path of the very last snapshot in
    current profile.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments

    Raises:
        SystemExit:     0
    """
    force_stdout = setQuiet(args)
    cfg = getConfig(args)
    _mount(cfg)
    sid = snapshots.lastSnapshot(cfg)
    if sid:
        if args.quiet:
            msg = '{}'
        else:
            msg = 'SnapshotPath: {}'
        print(msg.format(sid.path()), file=force_stdout)
    else:
        logger.error("There are no snapshots in '%s'" % cfg.profileName())
    if not args.keep_mount:
        _umount(cfg)
    sys.exit(RETURN_OK) 
Example #23
Source File: helpers.py    From appetite with Apache License 2.0 5 votes vote down vote up
def cmd_check(cmd):
    """Basic check for redirection in command"""

    try:
        results = next((False for param in shlex.split(cmd)
                        for rparam in REDIRECT_COMMANDS
                        if rparam == param), True)

        if not results:
            logger.warning("Possible injection", cmd=cmd)
    except Exception as error:
        logger.warning("Possible injection/weirdness", cmd=cmd, error=error.message) 
Example #24
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def takeSnapshot(cfg, force = True):
    """
    Take a new snapshot.

    Args:
        cfg (config.Config):    config that should be used
        force (bool):           take the snapshot even if it wouldn't need to
                                or would be prevented (e.g. running on battery)

    Returns:
        bool:                   ``True`` if there was an error
    """
    tools.envLoad(cfg.cronEnvFile())
    ret = snapshots.Snapshots(cfg).backup(force)
    return ret 
Example #25
Source File: snapshots.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def fileInfo(self):
        """
        Load/save "fileinfo.bz2"

        Args:
            d (FileInfoDict): dict of: {path: (permission, user, group)}

        Returns:
            FileInfoDict:     dict of: {path: (permission, user, group)}
        """
        d = FileInfoDict()
        infoFile = self.path(self.FILEINFO)
        if not os.path.isfile(infoFile):
            return d

        try:
            with bz2.BZ2File(infoFile, 'rb') as fileinfo:
                for line in fileinfo:
                    line = line.strip(b'\n')
                    if not line:
                        continue
                    index = line.find(b'/')
                    if index < 0:
                        continue
                    f = line[index:]
                    if not f:
                        continue
                    info = line[:index].strip().split(b' ')
                    if len(info) == 3:
                        d[f] = (int(info[0]), info[1], info[2]) #perms, user, group
        except (FileNotFoundError, PermissionError) as e:
            logger.error('Failed to load {} from snapshot {}: {}'.format(
                         self.FILEINFO, self.sid, str(e)),
                         self)
        return d 
Example #26
Source File: snapshots.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def fileInfo(self, d):
        assert isinstance(d, FileInfoDict), 'd is not FileInfoDict type: {}'.format(d)
        try:
            with bz2.BZ2File(self.path(self.FILEINFO), 'wb') as f:
                for path, info in d.items():
                    f.write(b' '.join((str(info[0]).encode('utf-8', 'replace'),
                                       info[1],
                                       info[2],
                                       path))
                                       + b'\n')
        except PermissionError as e:
            logger.error('Failed to write {}: {}'.format(self.FILEINFO, str(e)))

    #TODO: use @property decorator 
Example #27
Source File: helpers.py    From appetite with Apache License 2.0 5 votes vote down vote up
def __exit__(self, type, value, tb): # pylint: disable=redefined-builtin
        """Exit RunSingleInstance class
        :return: None
        """
        try:
            if not self.__is_running:
                fcntl.lockf(self.__filelock, fcntl.LOCK_UN)
                self.__filelock.close()
                os.unlink(self.__lockfile)
        except Exception as err:
            logger.error("Error unlocking single instance file", error=err.message) 
Example #28
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def _umount(cfg):
    """
    Unmount external filesystems.

    Args:
        cfg (config.Config):    config that should be used
    """
    try:
        mount.Mount(cfg = cfg).umount(cfg.current_hash_id)
    except MountException as ex:
        logger.error(str(ex)) 
Example #29
Source File: backintime.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def getConfig(args, check = True):
    """
    Load config and change to profile selected on commandline.

    Args:
        args (argparse.Namespace):
                        previously parsed arguments
        check (bool):   if ``True`` check if config is valid

    Returns:
        config.Config:  current config with requested profile selected

    Raises:
        SystemExit:     1 if ``profile`` or ``profile_id`` is no valid profile
                        2 if ``check`` is ``True`` and config is not configured
    """
    cfg = config.Config(config_path = args.config, data_path = args.share_path)
    logger.debug('config file: %s' % cfg._LOCAL_CONFIG_PATH)
    logger.debug('share path: %s' % cfg._LOCAL_DATA_FOLDER)
    logger.debug('profiles: %s' % ', '.join('%s=%s' % (x, cfg.profileName(x))
                                                        for x in cfg.profiles()))

    if 'profile_id' in args and args.profile_id:
        if not cfg.setCurrentProfile(args.profile_id):
            logger.error('Profile-ID not found: %s' % args.profile_id)
            sys.exit(RETURN_ERR)
    if 'profile' in args and args.profile:
        if not cfg.setCurrentProfileByName(args.profile):
            logger.error('Profile not found: %s' % args.profile)
            sys.exit(RETURN_ERR)
    if check and not cfg.isConfigured():
        logger.error('%(app)s is not configured!' %{'app': cfg.APP_NAME})
        sys.exit(RETURN_NO_CFG)
    if 'checksum' in args:
        cfg.forceUseChecksum = args.checksum
    return cfg 
Example #30
Source File: pluginmanager.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def logError(self, plugin, e):
        logger.error('Plugin %s %s failed: %s'
                     %(plugin.__module__,               #plugin name
                       sys._getframe(1).f_code.co_name, #method name
                       str(e)),                         #exception
                     self, 1)