def main(argv): if len(argv) != 3: print "thegatherer.py <language> <input> <output>" return 1 language, inpath, outpath = argv if not outpath.endswith('.db'): print "output path must end with .db" return 1 global INPATH INPATH = inpath try: os.unlink(outpath) except: pass global db db = sqlite3.connect(outpath) createdb(db) # Find all relevant files fileexts = extensionsForLanguage(language) filepaths = [] # Do everything in a transaction with db: parsePython(filepaths, inpath, outpath) with db: db.execute("ANALYZE") with db: db.execute("VACUUM")
def main(argv): if len(argv) != 3: print "gath-rb.py <language> <input> <output>" return 1 language, inpath, outpath = argv if not outpath.endswith('.db'): print "output path must end with .db" return 1 global INPATH INPATH = inpath issystem = '.rvm/rubies/' in inpath try: os.unlink(outpath) except: pass jsonstr = subprocess.check_output(['/usr/bin/env', 'ruby', 'script/gath-rb-ri.rb', inpath]).strip() print 'End' 'print jsonstr' j = json.loads(jsonstr) if not j or len(j) < 3: return 0 global db db = sqlite3.connect(outpath) createdb(db) print 'Begin' modules = [] for record in j: if record['type'] == 'namespace': modules.append(record['fullname']) allowedkeys = {'fullsource', 'superclass', 'visibility', 'canread', 'canwrite', 'issingleton', 'libraryisstdlib', 'libraryname', 'librarypath'} invalidKernelNames = set(['j', 'jj', 'p', 'pp']) with db: for record in j: #print record['fullname'] if record['type'] == 'method' or record['type'] == 'property': fullparents, _, name = record['fullname'].rpartition('#') else: fullparents, _, name = record['fullname'].rpartition('::') kind = record['type'] if fullparents == 'Kernel': fullparents = '' if kind == 'method': kind = 'function' if kind == 'class_method': continue if name in invalidKernelNames: continue if name.startswith('_'): continue if not name: continue if kind == 'method' or kind == 'class_method' or kind == 'function' or kind == 'property' or kind == 'class_property': if name[0].upper() == name[0]: # must be lowercase continue else: if name[0].lower() == name[0]: # must be uppercase continue if fullparents == '': namespace = '' parents = '' elif kind == 'method' or kind == 'class_method': namespace, _, parents = fullparents.rpartition('::') else: namespace = fullparents parents = '' #print ' ' + str((namespace, parents, name)) #pprint(record) if 'fullsignature' in record: fullsignature = record['fullsignature'] elif 'signature' in record: fullsignature = record['signature'] elif 'minisignature' in record: fullsignature = record['minisignature'] if 'minisignature' in record: signature = record['minisignature'] elif 'signature' in record: signature = record['signature'] elif 'fullsignature' in record: signature = record['fullsignature'] record['libraryisstdlib'] = False record['libraryname'] = '' record['librarypath'] = '' if issystem: full_combined_name = combine(namespace, parents, name) if namespace in stdlib19 or combine(namespace, parents) in stdlib19 or full_combined_name in stdlib19: record['libraryisstdlib'] = True else: shouldbreak = False for lib in stdlib_mapping: if full_combined_name in stdlib_mapping[lib]: record['libraryname'] = lib.partition('/')[0] record['librarypath'] = commonprefix(lib, record['librarypath']) #break else: for prefix in stdlib_mapping[lib]: if full_combined_name.startswith(prefix + '::'): record['libraryname'] = lib.partition('/')[0] record['librarypath'] = commonprefix(lib, record['librarypath']) #shouldbreak = True #break if shouldbreak: break # TODO: CONSTANTS # html = recordargs = { k: record[k] for k in record if k in allowedkeys } addRowRaw(db, namespace, parents, name, namespace, kind, signature, record['html'], fullsignature, **recordargs) # print modules with db: db.execute("ANALYZE") with db: db.execute("VACUUM")
import apifetch import createdb import currency apifetch() createdb() currency()