init from 4 old repositories

This commit is contained in:
2019-08-05 16:07:57 +03:00
parent c750e17675
commit fa1425a67b
20 changed files with 378 additions and 2 deletions

11
pylogextractor/README.md Normal file
View File

@@ -0,0 +1,11 @@
### pyLogExtractor
Simple tool for extracting specific strings from log files.
It could be useful for extracting all warnings or errors from
debug log or all specific user quotes from chat log.
pyLogExtractor requires Python 3.
Using:
Run python script, enter source path, path for save, and substring for searching.

104
pylogextractor/logextractor.py Executable file
View File

@@ -0,0 +1,104 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import re
import codecs
globalvars = {
"version": "0.92"
}
def searchuri():
prompt = ("File or directory for searching ["+
os.path.abspath(os.curdir)+"]:")
uri = input (prompt)
if uri == "":
uri = os.path.abspath(os.curdir)
return uri
if os.path.exists(uri):
if os.access(uri, os.R_OK):
return uri
else:
print ("You don't have permission to read "+uri+
". Try to change privileges or type another path.")
return searchuri()
else:
print ("File or directory not found. Plese type correct path.")
return searchuri()
def writefile():
prompt = ("File for writing[dump]:")
filename = input (prompt)
if filename == "":
filename = "dump"
try:
filedump = open(filename, 'x')
filedump.close()
return filename
except FileExistsError:
try:
filedump = open(filename, 'a')
filedump.close()
return filename
except PermissionError:
print ("You don't have permission to write "+filename)
return writefile()
except PermissionError:
print ("You don't have permission to write "+filename)
return writefile()
def substring():
prompt = ("Enter substring for search:")
substr = input (prompt)
if substr == "":
return substring()
return substr
if __name__ == "__main__":
print ("pyLogExtractor v",globalvars["version"])
uri = searchuri()
if os.path.isfile(uri):
print ("File for search: "+os.path.abspath(uri))
elif os.path.isdir(uri):
filesnumber = 0
for top, dirs, files in os.walk(uri):
filesnumber = (filesnumber + (len(files)))
print ("Directory for search: "+os.path.abspath(uri)+
" ("+str(filesnumber)+" files)")
filename = writefile()
print ("File for writing: "+filename)
substr = substring()
print ("Substring: "+substr)
filedump = open(filename, 'a')
stringsnumber = 0
if os.path.isdir(uri):
for top, dirs, files in os.walk(uri):
for nm in files:
with codecs.open(os.path.join(top, nm), "r",
encoding='utf-8', errors='ignore') as openedfile:
for currentstring in openedfile:
if currentstring.find(substr) > 0:
currentstring = (re.split(r': ',(re.sub(r'\<[^>]*\>',
'', currentstring))))[-1]
currentstring = (re.split(r'&gt; ',(re.sub(r'\<[^>]*\>',
'', currentstring))))[-1]
filedump.write(currentstring.rstrip() + '\n')
stringsnumber = stringsnumber + 1
openedfile.close()
elif os.path.isfile(uri):
print ("sdf")
with codecs.open(uri, "r",
encoding='utf-8', errors='ignore') as openedfile:
for currentstring in openedfile:
if currentstring.find(substr) > 0:
currentstring = (re.split(r': ',(re.sub(r'\<[^>]*\>',
'', currentstring))))[-1]
currentstring = (re.split(r'&gt; ',(re.sub(r'\<[^>]*\>',
'', currentstring))))[-1]
filedump.write(currentstring.rstrip() + '\n')
stringsnumber = stringsnumber + 1
openedfile.close()
filedump.close()
print (stringsnumber," strings added.")