diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2011-05-18 20:57:01 +0200 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2011-05-18 20:57:01 +0200 |
commit | 5819e83e0adeaeb477253366c80ecd5653eae04c (patch) | |
tree | fefc7a9e3cafa351ba506fa4197317722a4e6e39 | |
parent | Fixed so you can open files that is not pure uft8 (diff) | |
download | ebuildgen-5819e83e0adeaeb477253366c80ecd5653eae04c.tar.gz ebuildgen-5819e83e0adeaeb477253366c80ecd5653eae04c.tar.bz2 ebuildgen-5819e83e0adeaeb477253366c80ecd5653eae04c.zip |
Added a simple CLI
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | cli.py | 15 | ||||
-rw-r--r-- | scanfiles.py | 31 |
3 files changed, 33 insertions, 14 deletions
@@ -0,0 +1 @@ +Fix issues with UTF-8 encoded filenames @@ -0,0 +1,15 @@ +import argparse +import scanfiles + +parser = argparse.ArgumentParser(description="Scan dir for files") + +parser.add_argument("dir") +parser.add_argument("-t", "--types", metavar="filetype", nargs="+", + help="what filetypes it should scan") + +args = parser.parse_args() + +#print(args.dir) +#print(args.types) + +print(scanfiles.startscan(args.dir,args.types)) diff --git a/scanfiles.py b/scanfiles.py index 5944862..26ebb7e 100644 --- a/scanfiles.py +++ b/scanfiles.py @@ -3,22 +3,21 @@ import glob from ply import lex from ply import yacc -global_hfiles = set() -local_hfiles = set() - -def scandir(dir, filetype): +def scandir(dir, filetypes): files = [] dirs = [f for f in os.listdir(dir) if os.path.isdir(os.path.join(dir, f))] for dir_path in dirs: - files += scandir(dir + "/" + dir_path, filetype) - return files + glob.glob(dir + "/*" + filetype) + files += scandir(dir + "/" + dir_path, filetypes) + for filetype in filetypes: + files += glob.glob(dir + "/*" + filetype) + return files #print(scandir("/home/zed/Desktop/test/smw/", ".cpp")) #lex stuff begins here -def scanincludes(string): +def scanincludes(string,global_hfiles,local_hfiles): tokens = ( "INCLUDE", "GLOBH", @@ -90,14 +89,18 @@ def scanincludes(string): yacc.yacc() yacc.parse(string) + return(global_hfiles,local_hfiles) + + +def startscan(dir,filetypes): + global_hfiles = set() + local_hfiles = set() -input_string = "" + for file in scandir(dir, filetypes): + #print(file) -for file in scandir("/home/zed/Desktop/test/smw/", ".h"): - print(file) + with open(file, encoding="utf-8", errors="replace") as inputfile: + (global_hfiles,local_hfiles) = scanincludes(inputfile.read(),global_hfiles,local_hfiles) - with open(file, encoding="utf-8", errors="replace") as inputfile: - scanincludes(inputfile.read()) + return(global_hfiles,local_hfiles) -print(global_hfiles) -print(local_hfiles) |