def pack(packname, filtexpr, setexpr, packall): # tarfile 'filter' requires v2.7 if sys.version_info < (2, 7): raise Exception('Python 2.7 or later required..') # Get the root directory of cblib scriptdir = os.path.split(inspect.getfile(inspect.currentframe()))[0] rootdir = os.path.join(scriptdir, '..', '..') if not packall and setexpr != None: if os.path.isfile(setexpr): rootdir = os.path.dirname(setexpr) else: rootdir = setexpr # Find all instances files = list() cbfset = CBFset() cbfset.read(setexpr) filter(filtexpr, None, cbfset, lambda x: files.append(x)) if packall: # Find all instance information files = files + glob.glob(os.path.join(rootdir, 'instances', '*.csv')) files = files + glob.glob(os.path.join(rootdir, 'instances', '*.bib')) # Find all source files from 'tools' files = files + glob.glob(os.path.join(rootdir, 'tools', '*.c')) files = files + glob.glob(os.path.join(rootdir, 'tools', '*.h')) files = files + glob.glob(os.path.join(rootdir, 'tools', 'Makefile.*')) # Find all documents from 'docs' files = files + glob.glob(os.path.join(rootdir, 'docs', '*.pdf')) # Find all python files from 'scripts' files = files + glob.glob(os.path.join(rootdir, 'scripts', '*.py')) files = files + glob.glob( os.path.join(rootdir, 'scripts', 'admin', '*.py')) files = files + glob.glob( os.path.join(rootdir, 'scripts', 'data', '*.py')) files = files + glob.glob( os.path.join(rootdir, 'scripts', 'dist', '*.py')) files = files + glob.glob( os.path.join(rootdir, 'scripts', 'filters', '*.py')) files = files + glob.glob( os.path.join(rootdir, 'scripts', 'solvers', '*.py')) # Find all other important files files.append(os.path.join(rootdir, 'README')) files.append(os.path.join(rootdir, 'instances', 'cbf', 'README')) # Create compressed tar file print('Writing ' + packname + '.tar.gz') tar = tarfile.open(os.path.join(scriptdir, packname + '.tar.gz'), 'w:gz') for f in files: extractname = os.path.join(packname, os.path.relpath(f, rootdir)) print(extractname) tar.add(f, arcname=extractname, filter=addwritepermission) tar.close()
def reftable(out, filtexpr, setexpr): # Find the directory of this script scriptdir = os.path.split(inspect.getfile(inspect.currentframe()))[0] rootdir = os.path.join(scriptdir, '..', '..') # Default value if setexpr == None: setexpr = os.path.realpath( os.path.abspath(os.path.join(rootdir, 'instances', 'cbf'))) # Define files filemap = dict() cbfset = CBFset() cbfset.read(setexpr) filter.filter( filtexpr, None, cbfset, lambda x: files_add( cbfset.getpack(x, cbfset.rootdir), cbfset.getinstance(x), filemap)) # Define sorting convert = lambda text: int(text) if text.isdigit() else text alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key)] out.opentable() csvpath = os.path.join(rootdir, 'instances', 'ref.csv') csvfile = open(csvpath, 'rt') try: csvdialect = csv.Sniffer().sniff(csvfile.read(), ';\t') csvfile.seek(0) csvreader = csv.reader(csvfile, csvdialect, quotechar='"') next(csvreader) for row in csvreader: if row[0] in filemap: mylst = list(set(row[1].split(', ')) & filemap[row[0]]) if len(mylst) >= 1: mylst.sort(key=alphanum_key) out.addrow(row[0], mylst, row[2], row[3], row[4]) except Exception as e: print(str(e)) finally: csvfile.close() out.closetable()
'\n' ])) sys.exit(2) filtexpr = "" filelist = False setexpr = None for opt, arg in opts: if opt == '-s': setexpr = arg elif opt == '-f': filelist = True elif opt == "--filter": filtexpr = arg # Prepare set of instances if setexpr is not None: cbfset = CBFset() cbfset.read(setexpr) elif filelist: cbfset = CBFset() cbfset.readfilelist(args) else: cbfset = filter.defaultcbfset() try: update_autogen_tags(cbfset, filtexpr) except Exception as e: print(str(e))
filelist = False filtexpr = None setexpr = None statfile = args[0] for opt, arg in opts: if opt == "-f": filelist = True elif opt == "-s": setexpr = arg elif opt == "--filter": filtexpr = arg # Prepare set of instances if setexpr is not None: cbfset = CBFset() cbfset.read(setexpr) elif filelist: cbfset = CBFset() cbfset.readfilelist(args[1:]) else: cbfset = filter.defaultcbfset() # Apply filter if any if filtexpr: cbfset.filter(filtexpr) try: update_stattable(statfile, cbfset.cbffiles, cbfset.solfiles) except Exception as e: print(str(e))