diff options
author | 2011-06-09 22:19:40 +0200 | |
---|---|---|
committer | 2011-06-09 22:19:40 +0200 | |
commit | 51593a84c5ec650810a646950194ab04a96a22f4 (patch) | |
tree | 35d7068b4fcb7f811fa1f9290266a992a67042e3 | |
parent | Converted the output data from the makefiles to somethint useful (diff) | |
download | ebuildgen-51593a84c5ec650810a646950194ab04a96a22f4.tar.gz ebuildgen-51593a84c5ec650810a646950194ab04a96a22f4.tar.bz2 ebuildgen-51593a84c5ec650810a646950194ab04a96a22f4.zip |
You can now scan makefile projects with the cli
-rwxr-xr-x | cli.py | 5 | ||||
-rw-r--r-- | filetypes/ctypefiles.py | 3 | ||||
-rw-r--r-- | scanfiles.py | 36 |
3 files changed, 31 insertions, 13 deletions
@@ -25,9 +25,10 @@ args = parser.parse_args() #inclst is a list of includes. First in it is global then local. -inclst = scanfiles.startscan(args.dir,args.types) +inclst = scanfiles.scanproject(args.dir,"makefile") -print(inclst) +if args.ginc == args.linc == args.ifdef == False: + print(inclst) if args.ginc: print(inclst[0]) diff --git a/filetypes/ctypefiles.py b/filetypes/ctypefiles.py index 97e8561..ad62d44 100644 --- a/filetypes/ctypefiles.py +++ b/filetypes/ctypefiles.py @@ -151,8 +151,7 @@ def scanincludes(string,inclst,curdir): return(newinclst) def islocalinc(inc, curdir): - print(inc) - if glob.glob(curdir + inc) == []: + if glob.glob(curdir + "/" + inc) == []: return False else: return True diff --git a/scanfiles.py b/scanfiles.py index e59084f..081458f 100644 --- a/scanfiles.py +++ b/scanfiles.py @@ -7,13 +7,15 @@ def scandirfor(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, filetypes) for filetype in filetypes: files += glob.glob(dir + "/*" + filetype) + for dir_path in dirs: + files += scandirfor(dir + "/" + dir_path, filetypes) return files def scanmakefiledeps(makefile): + curdir = os.path.split(makefile)[0] + "/" + makefile = openfile(makefile) filestoscan = [] impfiles = [] #look for these files targets = scanmakefile(makefile) @@ -29,8 +31,10 @@ def scanmakefiledeps(makefile): deps = newdeps #impfiles.sort() - #print(impfiles) - return impfiles + for impfile in impfiles: + filestoscan.append(curdir + impfile) + #print(filestoscan) + return filestoscan def scanfilelist(filelist): global_hfiles = set() @@ -38,11 +42,25 @@ def scanfilelist(filelist): inclst = [global_hfiles,local_hfiles,{}] for file in filelist: - with open(file, encoding="utf-8", errors="replace") as inputfile: - inclst = scanincludes(inputfile.read(),inclst,os.path.split(file)[0]) + filestring = openfile(file) + if not filestring == None: + inclst = scanincludes(filestring,inclst,os.path.split(file)[0]) return(inclst) -fle = "/usr/portage/distfiles/svn-src/doneyet-read-only/trunk/Makefile" -with open(fle, encoding="utf-8", errors="replace") as inputfile: - scanmakefiledeps(inputfile.read()) +def scanproject(dir,projecttype): + if projecttype == "guess": + filestolookfor = ["Makefile","makefile"] #add more later + elif projecttype == "makefile": + filestolookfor = ["Makefile","makeifle"] + + mfile = scandirfor(dir, filestolookfor)[0] #use first file found + print(mfile) + return scanfilelist(scanmakefiledeps(mfile)) + +def openfile(file): + try: + with open(file, encoding="utf-8", errors="replace") as inputfile: + return inputfile.read() + except IOError: + print('cannot open', file) |