Python logger.debug() Examples

The following are 30 code examples of logger.debug(). 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: tools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def unInhibitSuspend(cookie, bus, dbus_props):
    """
    Release inhibit.
    """
    assert isinstance(cookie, int), 'cookie is not int type: %s' % cookie
    assert isinstance(bus, dbus.bus.BusConnection), 'bus is not dbus.bus.BusConnection type: %s' % bus
    assert isinstance(dbus_props, dict), 'dbus_props is not dict type: %s' % dbus_props
    try:
        interface = bus.get_object(dbus_props['service'], dbus_props['objectPath'])
        proxy = interface.get_dbus_method(dbus_props['methodUnSet'], dbus_props['interface'])
        proxy(cookie)
        logger.debug('Release inhibit Suspend')
        return None
    except dbus.exceptions.DBusException:
        logger.warning('Release inhibit Suspend failed.')
        return (cookie, bus, dbus_props) 
Example #2
Source File: deploy.py    From gimel with MIT License 6 votes vote down vote up
def role():
    new_role = False
    try:
        logger.info('finding role')
        iam('get_role', RoleName='gimel')
    except ClientError:
        logger.info('role not found. creating')
        iam('create_role', RoleName='gimel',
            AssumeRolePolicyDocument=ASSUMED_ROLE_POLICY)
        new_role = True

    role_arn = iam('get_role', RoleName='gimel', query='Role.Arn')
    logger.debug('role_arn={}'.format(role_arn))

    logger.info('updating role policy')

    iam('put_role_policy', RoleName='gimel', PolicyName='gimel',
        PolicyDocument=POLICY)

    if new_role:
        from time import sleep
        logger.info('waiting for role policy propagation')
        sleep(5)

    return role_arn 
Example #3
Source File: deploy.py    From cronyo with MIT License 6 votes vote down vote up
def role():
    new_role = False
    try:
        logger.info('finding role')
        iam('get_role', RoleName='cronyo')
    except ClientError:
        logger.info('role not found. creating')
        iam('create_role', RoleName='cronyo',
            AssumeRolePolicyDocument=ASSUMED_ROLE_POLICY)
        new_role = True

    role_arn = iam('get_role', RoleName='cronyo', query='Role.Arn')
    logger.debug('role_arn={}'.format(role_arn))

    logger.info('updating role policy')

    iam('put_role_policy', RoleName='cronyo', PolicyName='cronyo',
        PolicyDocument=POLICY)

    if new_role:
        from time import sleep
        logger.info('waiting for role policy propagation')
        sleep(5)

    return role_arn 
Example #4
Source File: config.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def removeOldCrontab(self, crontab):
        #We have to check if the self.SYSTEM_ENTRY_MESSAGE is in use,
        #if not then the entries are most likely from Back In Time 0.9.26
        #or earlier.
        if not self.SYSTEM_ENTRY_MESSAGE in crontab:
            #Then the system entry message has not yet been used in this crontab
            #therefore we assume all entries are system entries and clear them all.
            #This is the old behaviour
            logger.debug("Clearing all Back In Time entries", self)
            return [x for x in crontab if not 'backintime' in x]
        else:
            #clear all line peers which have a SYSTEM_ENTRY_MESSAGE followed by
            #one backintime command line
            logger.debug("Clearing system Back In Time entries", self)
            delLines = []
            for i, line in enumerate(crontab):
                if self.SYSTEM_ENTRY_MESSAGE in line and \
                    len(crontab) > i + 1 and        \
                    'backintime' in crontab[i + 1]:
                        delLines.extend((i, i + 1))
            return [line for i, line in enumerate(crontab) if i not in delLines] 
Example #5
Source File: configfile.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def setCurrentProfile(self, profile_id):
        """
        Change the current profile.

        Args:
            profile_id (str, int):  valid profile ID

        Returns:
            bool:                   ``True`` if successful
        """
        if isinstance(profile_id, int):
            profile_id = str(profile_id)
        profiles = self.profiles()

        for i in profiles:
            if i == profile_id:
                self.current_profile_id = profile_id
                logger.debug('change current profile: %s=%s'
                             % (profile_id, self.profileName(profile_id)),
                             self)
                logger.changeProfile(profile_id)
                return True

        return False 
Example #6
Source File: sshtools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def checkKnownHosts(self):
        """
        Check if the remote host is in current users ``known_hosts`` file.

        Raises:
            exceptions.KnownHost:   if the remote host wasn't found
                                    in ``known_hosts`` file
        """
        logger.debug('Check known hosts file', self)
        for host in (self.host, '[%s]:%s' % (self.host, self.port)):
            proc = subprocess.Popen(['ssh-keygen', '-F', host],
                                    stdout=subprocess.PIPE,
                                    universal_newlines = True)
            output = proc.communicate()[0] #subprocess.check_output doesn't exist in Python 2.6 (Debian squeeze default)
            if output.find('Host %s found' % host) >= 0:
                logger.debug('Host %s was found in known hosts file' % host, self)
                return True
        logger.debug('Host %s is not in known hosts file' %self.host, self)
        raise KnownHost(_('%s not found in ssh_known_hosts.') % self.host) 
Example #7
Source File: configfile.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def setCurrentProfileByName(self, name):
        """
        Change the current profile.

        Args:
            name (str): valid profile name

        Returns:
            bool:       ``True`` if successful
        """
        profiles = self.profiles()

        for profile_id in profiles:
            if self.profileName(profile_id) == name:
                self.current_profile_id = profile_id
                logger.debug('change current profile: %s' %name, self)
                logger.changeProfile(profile_id)
                return True

        return False 
Example #8
Source File: db_helper.py    From ns4_chatbot with Apache License 2.0 6 votes vote down vote up
def find_group_by_wechattype():
	#查询wechat所属组
	sql = "select DISTINCT(wechat_group) as wechat_group from biz_system_tree"
	logger.debug("sql:%s", sql)
	# conn = pymysql.connect(host="127.0.0.1",user="username",passwd="password",
	# 					  				   db="chatbot",
	# 					  				   charset="utf8")
	conn = __connection_pool.connection()
	cursor = conn.cursor()
	cursor.execute(sql)
	dutys = cursor.fetchall()

	wechat_groups  = []
	for d in dutys:
		wechat_groups.append(d['wechat_group'].decode('UTF-8'))

	cursor.close()
	conn.close()
	return wechat_groups 
Example #9
Source File: web_client.py    From ns4_chatbot with Apache License 2.0 6 votes vote down vote up
def send(apiUrl,data,method=None):
    logger.debug("调用内部系统[%s],data[%r]",apiUrl,data)
    try:
        data_json = json.dumps(data)
        headers = {'Content-Type': 'application/json'} # 设置数据为json格式,很重要
        request = urllib2.Request(url=apiUrl, headers=headers, data=data_json)
        if method is not None:
            request.get_method = method

        response = urllib2.urlopen(request)
        result = {'code':response.getcode(),'content':response.read()}
        logger.debug("调用[%s]返回结果:%r",apiUrl,result)
        return result
    except Exception as e:
        #traceback.print_stack()
        logger.exception(e,"调用内部系统[%s],data[%r],发生错误[%r]", apiUrl, data,e)
        return None 
Example #10
Source File: encfstools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def startProcess(self):
        """
        start 'encfsctl decode' process in pipe mode.
        """
        thread = password_ipc.TempPasswordThread(self.password)
        env = os.environ.copy()
        env['ASKPASS_TEMP'] = thread.temp_file
        with thread.starter():
            logger.debug('start \'encfsctl decode\' process', self)
            encfsctl = ['encfsctl', 'decode', '--extpass=backintime-askpass', self.encfs.path]
            logger.debug('Call command: %s'
                         %' '.join(encfsctl),
                         self)
            self.p = subprocess.Popen(encfsctl, env = env,
                                      stdin=subprocess.PIPE,
                                      stdout=subprocess.PIPE,
                                      universal_newlines = self.string,   #return string (if True) or bytes
                                      bufsize = 0) 
Example #11
Source File: encfstools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def startProcess(self):
        """
        start 'encfsctl encode' process in pipe mode.
        """
        thread = password_ipc.TempPasswordThread(self.password)
        env = self.encfs.env()
        env['ASKPASS_TEMP'] = thread.temp_file
        with thread.starter():
            logger.debug('start \'encfsctl encode\' process', self)
            encfsctl = ['encfsctl', 'encode', '--extpass=backintime-askpass', '/']
            logger.debug('Call command: %s'
                         %' '.join(encfsctl),
                         self)
            self.p = subprocess.Popen(encfsctl, env = env, bufsize = 0,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    universal_newlines = True) 
Example #12
Source File: encfstools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def checkVersion(self):
        """
        check encfs version.
        1.7.2 had a bug with --reverse that will create corrupt files
        """
        logger.debug('Check version', self)
        if self.reverse:
            proc = subprocess.Popen(['encfs', '--version'],
                                    stdout = subprocess.PIPE,
                                    stderr = subprocess.STDOUT,
                                    universal_newlines = True)
            output = proc.communicate()[0]
            m = re.search(r'(\d\.\d\.\d)', output)
            if m and StrictVersion(m.group(1)) <= StrictVersion('1.7.2'):
                logger.debug('Wrong encfs version %s' %m.group(1), self)
                raise MountException(_('encfs version 1.7.2 and before has a bug with option --reverse. Please update encfs')) 
Example #13
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def setTakeSnapshotMessage(self, type_id, message, timeout = -1):
        data = str(type_id) + '\n' + message

        try:
            with open(self.config.takeSnapshotMessageFile(), 'wt') as f:
                f.write(data)
        except Exception as e:
            logger.debug('Failed to set takeSnapshot message to %s: %s'
                         %(self.config.takeSnapshotMessageFile(), str(e)),
                         self)

        if 1 == type_id:
            self.snapshotLog.append('[E] ' + message, 1)
        else:
            self.snapshotLog.append('[I] '  + message, 3)

        try:
            profile_id =self.config.currentProfile()
            profile_name = self.config.profileName(profile_id)
            self.config.PLUGIN_MANAGER.message(profile_id, profile_name, type_id, message, timeout)
        except Exception as e:
            logger.debug('Failed to send message to plugins: %s'
                         %str(e),
                         self) 
Example #14
Source File: encfstools.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def path(self, path):
        """
        write plain path to encfsctl stdin and read encrypted path from stdout
        """
        if not 'p' in vars(self):
            self.startProcess()
        if not self.p.returncode is None:
            logger.warning('\'encfsctl encode\' process terminated. Restarting.', self)
            del self.p
            self.startProcess()
        self.p.stdin.write(path + '\n')
        ret = self.p.stdout.readline().strip('\n')
        if not len(ret) and len(path):
            logger.debug('Failed to encode %s. Got empty string'
                         %path, self)
            raise EncodeValueError()
        return ret 
Example #15
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def userName(self, uid):
        """
        Get the username for the given uid.
        uid->name will be cached to speed up subsequent requests.

        Args:
            uid (int):  User identifier (UID) to search for

        Returns:
            str:        name of the user with UID uid or '-' if not found
        """
        if uid in self.userCache:
            return self.userCache[uid]
        else:
            name = '-'
            try:
                name = pwd.getpwuid(uid).pw_name
            except Exception as e:
                logger.debug('Failed to get user name for UID %s: %s'
                             %(uid, str(e)),
                             self)

            self.userCache[uid] = name
            return name 
Example #16
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def smartRemoveKeepAll(self,
                           snapshots,
                           min_date,
                           max_date):
        """
        Return all snapshots between ``min_date`` and ``max_date``.

        Args:
            snapshots (list):           full list of :py:class:`SID` objects
            min_date (datetime.date):   minimum date for snapshots to keep
            max_date (datetime.date):   maximum date for snapshots to keep

        Returns:
            set:                        set of snapshots that should be keept
        """
        min_id = SID(min_date, self.config)
        max_id = SID(max_date, self.config)

        logger.debug("Keep all >= %s and < %s" %(min_id, max_id), self)

        return set([sid for sid in snapshots if sid >= min_id and sid < max_id]) 
Example #17
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def statFreeSpaceLocal(self, path):
        """
        Get free space on filsystem containing ``path`` in MiB using
        :py:func:`os.statvfs()`. Depending on remote SFTP server this might fail
        on sshfs mounted shares.

        Args:
            path (str): full path

        Returns:
            int         free space in MiB
        """
        try:
            info = os.statvfs(path)
            if info.f_blocks != info.f_bavail:
                return info.f_frsize * info.f_bavail // (1024 * 1024)
        except Exception as e:
            logger.debug('Failed to get free space for %s: %s'
                         %(path, str(e)),
                         self)
        logger.warning('Failed to stat snapshot path', self) 
Example #18
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def flockExclusive(self):
        """
        Block :py:func:`backup` from other profiles or users
        and run them serialized
        """
        if self.config.globalFlock():
            logger.debug('Set flock %s' %self.GLOBAL_FLOCK, self)
            self.flock = open(self.GLOBAL_FLOCK, 'w')
            fcntl.flock(self.flock, fcntl.LOCK_EX)
            #make it rw by all if that's not already done.
            perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | \
                    stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH
            s = os.fstat(self.flock.fileno())
            if not s.st_mode & perms == perms:
                logger.debug('Set flock permissions %s' %self.GLOBAL_FLOCK, self)
                os.fchmod(self.flock.fileno(), perms) 
Example #19
Source File: snapshots.py    From backintime with GNU General Public License v2.0 6 votes vote down vote up
def name(self):
        """
        Name of this snapshot

        Args:
            name (str): new name of the snapshot

        Returns:
            str:        name of this snapshot
        """
        nameFile = self.path(self.NAME)
        if not os.path.isfile(nameFile):
            return ''
        try:
            with open(nameFile, 'rt') as f:
                return f.read()
        except Exception as e:
            logger.debug('Failed to get snapshot {} name: {}'.format(
                         self.sid, str(e)),
                         self) 
Example #20
Source File: scrapertools.py    From tvalacarta with GNU General Public License v3.0 6 votes vote down vote up
def getCachedFile(siteCachePath,cacheId):
    mascara = os.path.join(siteCachePath,cacheId[:2],cacheId[2:],"*.cache")
    logger.debug("[scrapertools.py] mascara="+mascara)
    import glob
    ficheros = glob.glob( mascara )
    logger.debug("[scrapertools.py] Hay %d ficheros con ese id" % len(ficheros))

    cachedFile = ""

    # Si hay más de uno, los borra (serán pruebas de programación) y descarga de nuevo
    if len(ficheros)>1:
        logger.debug("[scrapertools.py] Cache inválida")
        for fichero in ficheros:
            logger.debug("[scrapertools.py] Borrando "+fichero)
            os.remove(fichero)
        
        cachedFile = ""

    # Hay uno: fichero cacheado
    elif len(ficheros)==1:
        cachedFile = ficheros[0]

    return cachedFile 
Example #21
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self,
                 cmd,
                 callback = None,
                 user_data = None,
                 filters = (),
                 parent = None,
                 conv_str = True,
                 join_stderr = True):
        self.cmd = cmd
        self.callback = callback
        self.user_data = user_data
        self.filters = filters
        self.currentProc = None
        self.conv_str = conv_str
        self.join_stderr = join_stderr
        #we need to forward parent to have the correct class name in debug log
        if parent:
            self.parent = parent
        else:
            self.parent = self

        if isinstance(self.cmd, list):
            self.pausable = True
            self.printable_cmd = ' '.join(self.cmd)
            logger.debug('Call command "%s"' %self.printable_cmd, self.parent, 2)
        else:
            self.pausable = False
            self.printable_cmd = self.cmd
            logger.warning('Call command with old os.system method "%s"' %self.printable_cmd, self.parent, 2) 
Example #22
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def writeCrontab(lines):
    """
    Write to users crontab.

    Note:
        This will overwrite the whole crontab. So to keep the old crontab and
        only add new entries you need to read it first with
        :py:func:`tools.readCrontab`, append new entries to the list and write
        it back.

    Args:
        lines (:py:class:`list`, :py:class:`tuple`):
                    lines that should be written to crontab

    Returns:
        bool:       ``True`` if successful
    """
    assert isinstance(lines, (list, tuple)), 'lines is not list or tuple type: %s' % lines
    with tempfile.NamedTemporaryFile(mode = 'wt') as f:
        f.write('\n'.join(lines))
        f.write('\n\n')
        f.flush()
        cmd = ['crontab', f.name]
        proc = subprocess.Popen(cmd,
                                stdout = subprocess.DEVNULL,
                                stderr = subprocess.PIPE,
                                universal_newlines = True)
        out, err = proc.communicate()
    if proc.returncode or err:
        logger.error('Failed to write lines to crontab: %s, %s'
                     %(proc.returncode, err))
        return False
    else:
        logger.debug('Wrote %s lines to users crontab'
                     %len(lines))
        return True 
Example #23
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def inhibitSuspend(app_id = sys.argv[0],
                    toplevel_xid = None,
                    reason = 'take snapshot',
                    flags = INHIBIT_SUSPENDING | INHIBIT_IDLE):
    """
    Prevent machine to go to suspend or hibernate.
    Returns the inhibit cookie which is used to end the inhibitor.
    """
    if ON_TRAVIS or dbus is None:
        # no suspend on travis (no dbus either)
        return
    if not app_id:
        app_id = 'backintime'
    try:
        if not toplevel_xid:
            toplevel_xid = 0
    except IndexError:
        toplevel_xid = 0

    for dbus_props in INHIBIT_DBUS:
        try:
            #connect directly to the socket instead of dbus.SessionBus because
            #the dbus.SessionBus was initiated before we loaded the environ
            #variables and might not work
            if 'DBUS_SESSION_BUS_ADDRESS' in os.environ:
                bus = dbus.bus.BusConnection(os.environ['DBUS_SESSION_BUS_ADDRESS'])
            else:
                bus = dbus.SessionBus()
            interface = bus.get_object(dbus_props['service'], dbus_props['objectPath'])
            proxy = interface.get_dbus_method(dbus_props['methodSet'], dbus_props['interface'])
            cookie = proxy(*[(app_id, dbus.UInt32(toplevel_xid), reason, dbus.UInt32(flags))[i] for i in dbus_props['arguments']])
            logger.debug('Inhibit Suspend started. Reason: {}'.format(reason))
            return (cookie, bus, dbus_props)
        except dbus.exceptions.DBusException:
            pass
    if isRoot():
        logger.debug("Inhibit Suspend failed because BIT was started as root.")
        return
    logger.warning('Inhibit Suspend failed.') 
Example #24
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def writeTimeStamp(fname):
    """
    Write current date and time into file ``fname``.

    Args:
        fname (str):        full path to timestamp file
    """
    now = datetime.now().strftime(BIT_TIME_FORMAT)
    logger.debug("write timestamp '%(time)s' into file '%(file)s'" %
                 {'time': now,
                  'file': fname})
    makeDirs(os.path.dirname(fname))
    with open(fname, 'w') as f:
        f.write(now) 
Example #25
Source File: sshtools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def checkCipher(self):
        """
        Try to login to remote host with the choosen cipher. This should make
        sure both `localhost` and the remote host support the choosen cipher.

        Raises:
            exceptions.MountException:  if login with the cipher failed
        """
        if not self.cipher == 'default':
            logger.debug('Check cipher', self)
            ssh = self.config.sshCommand(cmd = ['echo', '"Hello"'],
                                          custom_args = ['-o', 'Ciphers=%s' % self.cipher,
                                                         '-p', str(self.port),
                                                         self.user_host],
                                          port = False,
                                          cipher = False,
                                          user_host = False,
                                          nice = False,
                                          ionice = False,
                                          profile_id = self.profile_id)
            proc = subprocess.Popen(ssh,
                                    stdout=subprocess.DEVNULL,
                                    stderr=subprocess.PIPE,
                                    universal_newlines = True)
            err = proc.communicate()[1]
            if proc.returncode:
                logger.debug('Ciper %s is not supported' %self.config.SSH_CIPHERS[self.cipher], self)
                raise MountException(_('Cipher %(cipher)s failed for %(host)s:\n%(err)s')
                                      % {'cipher' : self.config.SSH_CIPHERS[self.cipher], 'host' : self.host, 'err' : err}) 
Example #26
Source File: mount.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self,
                 cfg = None,
                 profile_id = None,
                 tmp_mount = False,
                 parent = None):
        self.config = cfg
        if self.config is None:
            self.config = config.Config()

        self.profile_id = profile_id
        if self.profile_id is None:
            self.profile_id = self.config.currentProfile()

        self.tmp_mount = tmp_mount
        self.parent = parent

        if self.config.passwordUseCache(self.profile_id):
            cache = password.Password_Cache(self.config)
            action = None
            running = cache.status()
            if not running:
                logger.debug('pw-cache is not running', self)
                action = 'start'
            if running and not cache.checkVersion():
                logger.debug('pw-cache is running but is an old version', self)
                action = 'restart'
            bit = tools.which('backintime')
            if not action is None and not bit is None and len(bit):
                cmd = [bit, 'pw-cache', action]
                logger.debug('Call command: %s'
                             %' '.join(cmd), self)
                proc = subprocess.Popen(cmd,
                                        stdout = subprocess.DEVNULL,
                                        stderr = subprocess.DEVNULL)
                if proc.returncode:
                    logger.error('Failed to %s pw-cache: %s'
                                 %(action, proc.returncode),
                                 self)
                    pass 
Example #27
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def stop(self):
        """
        Stop the daemon
        """
        if not self.pidfile:
            logger.debug("Unattended daemon can't be stopped. No PID file", self)
            return

        # Get the pid from the pidfile
        pid, procname = self.appInstance.readPidFile()

        if not pid:
            message = "pidfile %s does not exist. Daemon not running?\n"
            logger.error(message % self.pidfile, self)
            return # not an error in a restart

        # Try killing the daemon process
        try:
            while True:
                os.kill(pid, signal.SIGTERM)
                sleep(0.1)
        except OSError as err:
            if err.errno == errno.ESRCH:
                #no such process
                self.appInstance.exitApplication()
            else:
                logger.error(str(err), self)
                sys.exit(1) 
Example #28
Source File: snapshotlog.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def get(self, mode = None, decode = None, skipLines = 0):
        """
        Read the log, filter and decode it and yield its lines.

        Args:
            mode (int):                 Mode used for filtering. Take a look at
                                        :py:class:`snapshotlog.LogFilter`
            decode (encfstools.Decode): instance used for decoding lines or ``None``
            skipLines (int):            skip ``n`` lines before yielding lines.
                                        This is used to append only new lines
                                        to LogView

        Yields:
            str:                        filtered and decoded log lines
        """
        logFilter = LogFilter(mode, decode)
        count = logFilter.header.count('\n')
        try:
            with open(self.logFileName, 'rt') as f:
                if logFilter.header and not skipLines:
                    yield logFilter.header
                for line in f.readlines():
                    line = logFilter.filter(line.rstrip('\n'))
                    if not line is None:
                        count += 1
                        if count <= skipLines:
                            continue
                        yield line
        except Exception as e:
            msg = ('Failed to get take_snapshot log from {}:'.format(self.logFile), str(e))
            logger.debug(' '.join(msg), self)
            for line in msg:
                yield line 
Example #29
Source File: tools.py    From backintime with GNU General Public License v2.0 5 votes vote down vote up
def reload(self):
        """
        send SIGHUP signal to process
        """
        if not self.pidfile:
            logger.debug("Unattended daemon can't be reloaded. No PID file", self)
            return

        # Get the pid from the pidfile
        pid, procname = self.appInstance.readPidFile()

        if not pid:
            message = "pidfile %s does not exist. Daemon not running?\n"
            logger.error(message % self.pidfile, self)
            return

        # Try killing the daemon process
        try:
            os.kill(pid, signal.SIGHUP)
        except OSError as err:
            if err.errno == errno.ESRCH:
                #no such process
                self.appInstance.exitApplication()
            else:
                sys.stderr.write(str(err))
                sys.exit(1) 
Example #30
Source File: scrapertools.py    From tvalacarta with GNU General Public License v3.0 5 votes vote down vote up
def getCacheFileNames(url):

    # Obtiene el directorio de la cache para esta url
    siteCachePath = getSiteCachePath(url)
        
    # Obtiene el ID de la cache (md5 de la URL)
    cacheId = get_md5(url)
        
    logger.debug("[scrapertools.py] cacheId="+cacheId)

    # Timestamp actual
    nowtimestamp = time.strftime("%Y%m%d%H%M%S", time.localtime())
    logger.debug("[scrapertools.py] nowtimestamp="+nowtimestamp)

    # Nombre del fichero
    # La cache se almacena en una estructura CACHE + URL
    ruta = os.path.join( siteCachePath , cacheId[:2] , cacheId[2:] )
    newFile = os.path.join( ruta , nowtimestamp + ".cache" )
    logger.debug("[scrapertools.py] newFile="+newFile)
    if not os.path.exists(ruta):
        os.makedirs( ruta )

    # Busca ese fichero en la cache
    cachedFile = getCachedFile(siteCachePath,cacheId)

    return cachedFile, newFile 

# Busca ese fichero en la cache