<s> import os <EOL> import logging <EOL> import socket <EOL> import subprocess <EOL> import re <EOL> import psutil <EOL> from netifaces import interfaces , ifaddresses , AF_INET <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> def enum ( ** enums ) : <EOL> return type ( '<STR_LIT>' , ( ) , enums ) <EOL> def GetProcessEnv ( pid = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> env = { } <EOL> try : <EOL> envlist = open ( '<STR_LIT>' % pid ) . read ( ) . split ( '<STR_LIT>' ) <EOL> except : <EOL> return env <EOL> for e in envlist : <EOL> ( k , _ , v ) = e . partition ( '<STR_LIT:=>' ) <EOL> ( k , v ) = ( k . strip ( ) , v . strip ( ) ) <EOL> if not k : <EOL> continue <EOL> env [ k ] = v <EOL> return env <EOL> def process_is_crawler ( proc ) : <EOL> try : <EOL> cmdline = ( proc . cmdline ( ) if hasattr ( proc . cmdline , '<STR_LIT>' <EOL> ) else proc . cmdline ) <EOL> curr = psutil . Process ( os . getpid ( ) ) <EOL> curr_cmdline = ( <EOL> curr . cmdline ( ) if hasattr ( <EOL> curr . cmdline , <EOL> '<STR_LIT>' ) else curr . cmdline ) <EOL> if cmdline == curr_cmdline : <EOL> return True <EOL> except Exception : <EOL> pass <EOL> return False <EOL> class NullHandler ( logging . Handler ) : <EOL> def emit ( self , record ) : <EOL> pass <EOL> def get_errno_msg ( libc ) : <EOL> try : <EOL> import ctypes <EOL> libc . __errno_location . restype = ctypes . POINTER ( ctypes . c_int ) <EOL> errno = libc . __errno_location ( ) . contents . value <EOL> errno_msg = os . strerror ( errno ) <EOL> return errno_msg <EOL> except Exception : <EOL> return '<STR_LIT>' <EOL> def get_host_ipaddr ( ) : <EOL> s = socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) <EOL> try : <EOL> s . connect ( ( '<STR_LIT>' , <NUM_LIT:9> ) ) <EOL> return s . getsockname ( ) [ <NUM_LIT:0> ] <EOL> except socket . error : <EOL> return socket . gethostname ( ) <EOL> finally : <EOL> del s <EOL> def get_host_ip4_addresses ( ) : <EOL> ip_list = [ ] <EOL> for interface in interfaces ( ) : <EOL> if AF_INET in ifaddresses ( interface ) : <EOL> for link in ifaddresses ( interface ) [ AF_INET ] : <EOL> ip_list . append ( link [ '<STR_LIT>' ] ) <EOL> return ip_list <EOL> def find_mount_point ( path ) : <EOL> path = os . path . abspath ( path ) <EOL> while not os . path . ismount ( path ) : <EOL> path = os . path . dirname ( path ) <EOL> return path <EOL> def log_atime_config ( path , crawlmode ) : <EOL> atime_config = '<STR_LIT>' <EOL> mountlocation = find_mount_point ( path = path ) <EOL> logger . info ( '<STR_LIT>' <EOL> % ( path , mountlocation ) ) <EOL> if crawlmode == '<STR_LIT>' : <EOL> grepstr = '<STR_LIT>' % mountlocation <EOL> try : <EOL> mount = subprocess . Popen ( '<STR_LIT>' , stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> mountlist = subprocess . Popen ( <EOL> ( '<STR_LIT>' , <EOL> grepstr ) , <EOL> stdin = mount . stdout , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) <EOL> mountlist_arr = mountlist . stdout . read ( ) . split ( '<STR_LIT:\n>' ) <EOL> if len ( mountlist_arr ) > <NUM_LIT:0> : <EOL> ptrn = r'<STR_LIT>' <EOL> match = re . search ( ptrn , mountlist_arr [ <NUM_LIT:0> ] ) <EOL> for i in match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:U+002C>' ) : <EOL> if i . strip ( ) == '<STR_LIT>' : <EOL> atime_config = '<STR_LIT>' <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % atime_config ) <EOL> break <EOL> elif i . strip ( ) == '<STR_LIT>' : <EOL> atime_config = '<STR_LIT>' <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % atime_config ) <EOL> break <EOL> elif i . strip ( ) == '<STR_LIT>' : <EOL> atime_config = '<STR_LIT>' <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % atime_config ) <EOL> break <EOL> if atime_config == '<STR_LIT>' : <EOL> atime_config = '<STR_LIT>' <EOL> logger . debug ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % atime_config ) <EOL> except OSError as e : <EOL> logger . error ( '<STR_LIT>' + <EOL> '<STR_LIT>' % e . errno + e . strerror + <EOL> '<STR_LIT>' + type ( e ) . __name__ + '<STR_LIT:]>' ) <EOL> logger . info ( "<STR_LIT>" % ( mountlocation , <EOL> atime_config ) ) <EOL> if atime_config == '<STR_LIT>' : <EOL> logger . info ( '<STR_LIT>' <EOL> ) <EOL> if atime_config == '<STR_LIT>' : <EOL> logger . info ( <EOL> '<STR_LIT>' ) <EOL> if atime_config == '<STR_LIT>' : <EOL> logger . info ( '<STR_LIT>' <EOL> ) <EOL> if atime_config == '<STR_LIT>' : <EOL> logger . info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return atime_config <EOL> def is_process_running ( pid ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . kill ( pid , <NUM_LIT:0> ) <EOL> except OSError : <EOL> return False <EOL> else : <EOL> return True </s>
