Server IP : 80.241.246.6 / Your IP : 216.73.216.167 Web Server : Apache/2.4.25 (Debian) System : Linux kharagauli 4.9.0-19-amd64 #1 SMP Debian 4.9.320-2 (2022-06-30) x86_64 User : www-data ( 33) PHP Version : 7.0.33-0+deb9u12 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/kharagauli_new/ |
Upload File : |
#__author__ = 'suxoza' import sys,os try: #from dict_dir import A from optparse import OptionParser except ImportError: sys.exit("no optparse module found") class MyError(Exception):pass #-i /var/www/eruditor/view -e .html -t b -s paliko #-i /var/www/eruditor/view -e .html -t b -s paliko -r "saxli shaliko" #-i /var/www/eruditor/view -e .html -t b -s "\"http://www.onlineolimpiada/\"" #-i /var/www/eruditor/view -e .html -t b -s "\"http://www.onlineolimpiada/\"" -r "\"http://www.onlineolimpiada/new/\"" class Repl: def __init__(self,kwargs): try: self.input = kwargs['input'] self.search = kwargs['search'] self.replace = kwargs['replace'] self.type = kwargs['type'] self.end = kwargs['end'] self.iterator = 0 self.action = 'search_' if not self.replace else 'replace_' except KeyError: print("parameters error") def find(self): if not os.path.exists(self.input):raise MyError("input path not found!!!") self.ret_array = [] self.iterator = 0 for (a,b,c) in os.walk(self.input): for file in c: if not os.path.isfile(os.path.join(a,file)):continue if self.end: if not file.endswith(self.end):continue file_name = os.path.join(a,file) getattr(self,self.action)(file_name) for x in self.ret_array: print(x) print('sum:',self.iterator) def replace_(self,file): iter,line = 0,0 mode = 'r' if self.type == 's' else 'rb' mode_w = 'w' if self.type == 's' else 'wb' count_ = 0 line_ = [] ret = "".encode() with open(file,mode) as op: for x in op: line += 1 if self.search.encode() in x: ret += x.replace(self.search.encode(),self.replace.encode()) line_.append(line) len_ = len(x.split(self.search.encode())) - 1 count_ += len_ self.iterator += len_ else: ret += x if count_: self.ret_array.append(dict(count = count_,file = file,line = line_)) with open(file,mode_w) as w: w.write(ret) def search_(self,file): iter,line = 0,0 mode = 'r' if self.type == 's' else 'rb' count_ = 0 line_ = [] with open(file,mode) as op: for x in op: line += 1 if self.search.encode() in x: line_.append(line) len_ = len(x.split(self.search.encode())) - 1 count_ += len_ self.iterator += len_ if count_:self.ret_array.append(dict(count = count_,file = file,line = line_)) if __name__ == "__main__": parser = OptionParser() parser.add_option("-i", "--input", dest="input",help="input file")#myfindfile parser.add_option("-s", "--search", dest="search",help="search string") # -s paliko parser.add_option("-r", "--replace", dest="replace",help="search string") # -r shaliko parser.add_option("-t", "--type", dest="type",help="binary or string",default="b") # -t s || b parser.add_option("-e", "--end", dest="end",help="endswith") # -e .py (options, args) = parser.parse_args() a = Repl(vars(options)) a.find()