def guess(self): if self.grammarlist == None: from pydsl.Guess import guess self.grammarlist = guess(self) return self.grammarlist
DEBUGLEVEL = 39 if ARGS.debuglevel: DEBUGLEVEL = ARGS.debuglevel logging.basicConfig(level = DEBUGLEVEL) inputstr = "" from pydsl.Guess import guess, guess_filename if (ARGS.inputfile): from pydsl.Interaction.Protocol import protocol_split pdict = protocol_split(ARGS.inputfile) if pdict["protocol"] == "file": try: with open(pdict["path"], "rb") as f: inputstr = f.read() except IOError: inputstr = "" result = guess(inputstr) result = result.union(guess_filename(ARGS.inputfile)) elif pdict["protocol"] == "http": import urllib.request f = urllib.request.urlopen(ARGS.inputfile); inputstr = f.read() f.close() result = guess(inputstr) else: try: with open(ARGS.inputfile, "rb") as f: inputstr = f.read() except IOError: inputstr = "" result = guess(inputstr) elif (ARGS.expression):
_,_,_,destformat = getFileTuple(ARGS.outputfile) destformat = destformat[1:] #Quitamos el punto LOG.warning("Destination format:" + destformat) if (ARGS.inputfile and ARGS.outputfile): import os if not os.path.exists(ARGS.inputfile): print("input file doesn't exists") sys.exit(-1) inputfile = "file://" + ARGS.inputfile inputformat = ARGS.inputformat if not inputformat: from pydsl.Memory.Storage.Dict import FileTypeDictStorage ftdl = FileTypeDictStorage() from pydsl.Guess import guess inputformat = guess(inputfile, [ftdl]) if len(inputformat) == 0: print("Input format not found") sys.exit(-1) elif len(inputformat) > 1: print("Several input formats found, please use -i argument") sys.exit(-1) inputformat = inputformat.pop() LOG.warning("Inputformat:" + inputformat) from pydsl.Memory.Storage.Directory.Function import TransformerDirStorage from pydsl.Search.Searcher import MemorySearcher from pydsl.Search.Indexer import Indexer searcher = MemorySearcher([Indexer(TransformerDirStorage())]) print(searcher.search("output="+destformat+"&&input="+inputformat)) searchresult = searcher.search("output="+destformat+"&&input="+inputformat)