Vorgestern war es wieder soweit das ich paar sachen suchte, wo ich wusste sie sind in div. conf files, aber in welchen ?? Da hab ich mir ein Programm für genau dieses Dillema geschrieben.
Meine English kenntnisse sind einigermasen ok, aber die grammatik nicht so, also allg. verbesserungs vorschläge sind gerne gesehen, zum Code und zum "english"


und hier das "schöne" stück:
Code: Alles auswählen
#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-
# ToDo:
# 1. Make Argument test with "modul argparse".
from sys import argv, exit
from getpass import getuser
from time import time
import os
def searching(root, extension, term):
# Walk recursive from root parameter open all the files with,
# the right extension and stoping the running time to solve the
# search.
start_time = time()
file_counter = 0
for (path, dir, files) in os.walk(root):
for element in files:
if element.endswith(extension):
path_file = os.path.join(path, element)
# sfile = ScanningFile.
with open(path_file, "r", encoding="ISO-8859-1") as sfile:
# rsfile = Read-Scanning-File.
rsfile = sfile.read()
if term in rsfile:
print("found @ {}/{}".format(path,
element))
file_counter += 1
else:
pass
print("\n!-----------------------------------------!\n")
print("\"{}\" in {} files found. run {} Seconds\n".format(term,
file_counter, int((time() - start_time))))
print("!-----------------------------------------!\n")
def main():
# The main function, testing user and arguments and go to the search.
if getuser() != 'root':
print("\nMust run as root\n")
exit(0)
if len(argv) != 4:
print("\nNeed Arguments like:\ninfise <root> <file_extension> <Term>\n")
exit(0)
else:
root = str(argv[1])
extension = str(argv[2])
term = str(argv[3])
searching(root, extension, term)
if __name__=='__main__':
main()
Edit:
Eine frage noch, wen ich z.b.
Code: Alles auswählen
from os import path, walk
Code: Alles auswählen
path_file = path.join(path, element)
Hat da jemand ein tipp ?