def check_file_list(any_format,ignore_warnings=True, warnings=[]):
    """
    get the folder for the job or a batch job
    a batch job can be either a readable text file name: file_name.any_extension - contents must be file with list of folders, one per line
    or it can be a glob-like search pattern for folders//*
    the folders may or may not contain valid tif data with well-named frames
    if any are invalid, the invalid ones are added to warnings. the valid ones are returned in a list
    a caller can decide what to do about the warnings which will be listed (ignore/quit)
    If print_info==True:
    the following folders can be processed:
    folder range #gaps 
    the following cannot be processed:
    folder issue
    """
    import os
    from glob import glob
    folders = [any_format]
    if os.is_file(any_format):
        with open(any_format) as f: folders = [_f for _f in f]
    if any_format[-1]=="*":  folders = list(glob(any_format))
    valid_folders = []
    for f in folders:
        c = context.folder_context(f)
        if not c.meta_key["valid"]: warnings.append(f)
        else: valid_folders.append(c.meta_key)
          
    #list the goods and the bads by simply listing the info for the folder but then say warnings in tabs if req
    
    if ignore_warnings == False and len(warnings) > 0:
        #some folders cannot be processed. Do you want to continue(y) or quit(n)?
        pass
            
    return valid_folders
Пример #2
0
def serverStart(kwargs={}):
    app = Bottle()
    appConfig = AppConfig()
    bottle.TEMPLATES.clear()

    # register routes
    for appRoute in appConfig.registerRoutes():
        app.route(appRoute[0], appRoute[1], appRoute[2])

    # start system cleaner
    SystemCleaner().startCleaner()

    serverOptions = appConfig.severOptions()
    host = serverOptions.get('host') if not kwargs.get('host') else kwargs.get('host')
    port = serverOptions.get('port') if not kwargs.get('port') else kwargs.get('port')
    reloader = serverOptions.get('reloader') if not kwargs.get('reloader') else kwargs.get('reloader')
    debug = serverOptions.get('debug') if not kwargs.get('debug') else kwargs.get('debug')
    server = serverOptions.get('server') if not kwargs.get('server') else kwargs.get('server')
    interval = serverOptions.get('interval') if not kwargs.get('interval') else kwargs.get('interval')
    certfile = serverOptions.get('ssl').get('certfile') if not kwargs.get('certfile') else kwargs.get('certfile')
    keyfile = serverOptions.get('ssl').get('keyfile') if not kwargs.get('keyfile') else kwargs.get('keyfile')
    
    if os.access(os.getcwd(), os.W_OK) or (os.is_file(appserverPIDFile) and os.access(appserverPIDFile, os.W_OK)):
        # try to check the address already bind or not
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        alreadyRun = False
        try:
            s.bind((host, port))
            writePID(str(os.getpid()))

        except Exception as ex:
            alreadyRun = True
            print('server already running or address already in used {}:{} -> {}'.format(host, port, ex))

            # if in debug mode try kill the server and force alradyRun to false
            if reloader and debug:
                serverStop(kwargs)
                alreadyRun = False

        finally:
            s.close()

        if not alreadyRun:
            overrideBuiltinPrint()

            if certfile is None or keyfile is None:
                run(app=app, host=host, port=port, reloader=reloader, debug=debug, server=server, interval=interval)

            else:
                run(app=app, host=host, port=port, reloader=reloader, debug=debug, server=server, interval=interval, certfile=certfile, keyfile=keyfile)

    else:
        print('''You don't have write access to {}, need read write access!'''.format(os.getcwd()))
Пример #3
0
    async def _font(self, url: str=None):
        """Allows you to set the font that the fortune cookies are shown in.
           Only accepts ttf."""
        option = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0)'
                  ' Gecko/20100101 Firefox/40.1'}

        if url is None :
            url = "https://cdn.discordapp.com/attachments/218222973557932032/240223136447070208/FortuneCookieNF.ttf"
            if os.is_file("data/horoscope/FortuneCookieNF.ttf"):
                return
            else:
                async with aiohttp.request("GET", url, headers=option) as resp:
                    test = await resp.read()
                    with open("data/horoscope/FortuneCookieNF.ttf", "wb") as f:
                        f.write(test)
        elif not url.endswith("ttf"):
            await self.bot.say("This is not a .ttf font, please use a .ttf font. Thanks")
            return
        await self.bot.say("Font has been saved")
Пример #4
0
    async def _font(self, url: str=None):
        """Allows you to set the font that the fortune cookies are shown in.
           Only accepts ttf."""
        option = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0)'
                  ' Gecko/20100101 Firefox/40.1'}

        if url is None :
            url = "https://cdn.discordapp.com/attachments/218222973557932032/240223136447070208/FortuneCookieNF.ttf"
            if os.is_file("data/horoscope/FortuneCookieNF.ttf"):
                return
            else:
                async with self.session.get(url, headers=option) as resp:
                    test = await resp.read()
                    with open("data/horoscope/FortuneCookieNF.ttf", "wb") as f:
                        f.write(test)
        elif not url.endswith("ttf"):
            await self.bot.say("This is not a .ttf font, please use a .ttf font. Thanks")
            return
        await self.bot.say("Font has been saved")
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.tree import DecisionTreeClassifier

import os



# Data set in csv file
DATA_SET_CSV = "assets/datasets/train.csv"

if not os.is_file(DATA_SET_CSV):
      print("The file is missing...")

# Read data from csv file.
data = pd.read_csv("assets/datasets/train.csv").as_matrix()
classifier = DecisionTreeClassifier()

xtrain = data[0:21000, 1:]
train_label = data[0:21000, 0]

classfier.fit(xtrain, train_label)

# testing
xtest = data[21000:, 1:]
actual_label = data[21000:, 0]

def main(number):
    digit = xtest[number]
    digit.shape = (28, 28)
Пример #6
0
 def listing(self):
     return [
         CacheEntry.from_filename(e)
         for e in os.listdir(self.base_dir)
         if os.is_file(e) and not e.startswith('.')
     ]
Пример #7
0
def align(file1, file2, e):
    aln = subprocess.check_output((f'locarna --struct-local=1 {file1} {file2}'), shell=True, stderr=e)
    aln_score = int(aln.decode('utf-8').split('\n')[0].split(' ')[1])
    return aln_score


def load_rs_values(rs_file):
    with open(rd_dir + rs_self_file, 'r') as fh:
        csv_reader = reader(fh)
        for line in csv_reader:
            rs_list[line[0]] = line[1]
    return rs_list


if os.is_file(rd_dir + rs_self_file):
    rs_list = load_rs_values(rd_dir + rs_self_file)
else: 
    rs_files = os.listdir(rs_dir)
    e = open('err.txt', 'w')
    with open(rd_dir + rs_self_file, 'w') as fh:
    for rs_file in rs_files:
        token = rs_file.split('_')[1]
        ref_score = align(rs_dir + rs_file,rs_dir + rs_file, e) # can we move this to outside the j loop and into the i loop,
        fh.write(f'{token},{ref_score}')
    rs_list = load_rs_values(rd_dir + rs_self_file)


utr_names = [x.split('.')[0].split('_')[-1] for x in utr_files]

for i in range(len(utr_files)):
Пример #8
0
def main():
    parser = argparse.ArgumentParser(description="Manage multiple shell history files")
    parser.add_argument(
        '--update', '-u', action='store_true',
        help='Update existing history and TOC files (if needed)'
    )
    parser.add_argument(
        '--init', '-i', action='store_true',
        help='Ensure the existence of merge and TOC files'
    )
    parser.add_argument(
        '--histdir', '-d', default=os.environ.get("SHELL_HISTDIR"),
        help='Path to store per-shell and merged history files'
    )
    parser.add_argument(
        '--shellfile', '-s', default=os.environ.get("SHELL_HISTFILE"),
        help='History file for commands entered in this shell'
    )
    parser.add_argument(
        '--prune', '-p', action='store_true',
        help='Delete merge and TOC files'
    )
    parser.add_argument(
        '--dry-run', action='store_true',
        help='Do nothing, print what actions would be taken'
    )

    args = vars(parser.parse_args())

    histdir = args.get('histdir')
    shellhist = args.get('shellfile')
    dry_run = args.get('dry_run')

    if dry_run:
        print("Got --dry-run, will not modify files")

    if not (
        os.path.isdir(histdir)
        and os.access(histdir, os.W_OK)
        and os.access(histdir, os.R_OK)
    ):
        print("multihist: history directory '%s' is not a read/writable directory" % histdir)
        sys.exit(-1)

    shell_stats, merged_stats = stat_shell_histories(histdir)
    shell_stats.sort(key=lambda e: e[1])
    merged_stats.sort(key=lambda e: e[1])
    newest_mergetime = merged_stats[-1][1] if merged_stats else 0
    newest_shelltime = shell_stats[-1][1] if shell_stats else 0

    mergefiles = [m[0] for m in merged_stats]
    do_rebuild = False

    if args.get('prune'):
        for mergefile in mergefiles:
            if os.is_file(mergefile):
                if dry_run:
                    print("Remove mergefile %s" % mergefile)
                else:
                    os.remove(mergefile)
            tocfilename = mergefile.replace('merged-', 'toc-')
            if os.is_file(tocfilename):
                if dry_run:
                    print("Remove TOC file %s" % tocfilename)
                else:
                    os.remove(tocfilename)

    mergefilename = shellhist.replace('shell-', 'merged-')

    if mergefilename not in mergefiles:
        do_rebuild = True
        mergefiles.append(mergefilename)

    if args.get('init'):
        if dry_run:
            print("Initializing, will update merge files...")
        do_rebuild = True

    elif args.get('update'):
        if newest_shelltime > newest_mergetime:
            if dry_run:
                print("Will update, mergefile timestamp %s older than %s" % (
                    newest_shelltime, newest_mergetime))
            do_rebuild = True

    if do_rebuild:
        for mergefile in mergefiles:
            build_mergefile(mergefile, newest_mergetime, shell_stats, dry_run)
Пример #9
0
 def set_target_xml(self, xml_path):
     if os.is_file(xml_path, follow_symlinks=False):
         self.last_tree = ET.parse(xml_path)
         return True
     return False