From 51593a84c5ec650810a646950194ab04a96a22f4 Mon Sep 17 00:00:00 2001 From: Sebastian Parborg Date: Thu, 9 Jun 2011 22:19:40 +0200 Subject: You can now scan makefile projects with the cli --- cli.py | 5 +++-- filetypes/ctypefiles.py | 3 +-- scanfiles.py | 36 +++++++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/cli.py b/cli.py index 1c9ee22..29fa7e6 100755 --- a/cli.py +++ b/cli.py @@ -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) -- cgit v1.2.3-65-gdbad