Exemple #1
0
def is_f77_gnu(env):
    """Returns true if F77 in env is a Gnu fortran
    compiler."""
    # XXX: do this properly
    if env.has_key('F77'):
        fullpath = env['F77']
        return pbasename(fullpath) == 'g77' or pbasename(fullpath) == 'gfortran'
    else:
        return False
Exemple #2
0
def is_f77_gnu(env):
    """Returns true if F77 in env is a Gnu fortran
    compiler."""
    # XXX: do this properly
    if env.has_key('F77'):
        fullpath = env['F77']
        return pbasename(fullpath) == 'g77' or pbasename(
            fullpath) == 'gfortran'
    else:
        return False
def createAllCredits(path):
    fm = FolderManager()
    subs, imp = findAllSubmissionFolders(path)
    total = []
    extra = []

    curParent = path
    sheetNr = ''
    while True:
        tmp = pdirname(curParent)
        if tmp == curParent:
            raise ValueError("U can't use this script here!")
        curParent = tmp
        if rcompile('Blatt_\d\d').match(pbasename(curParent)):
            sheetNr = pbasename(curParent).split('_')[1]
            break

    for subpath in subs:
        for tup in createCreditsText(subpath):
            total.append((tup[0], [('%.2f' % x).zfill(5) for x in tup[1]]))

    for subpath in imp:
        for tup in createCreditsText(subpath):
            searchRes = fm.findStudentByName(tup[0], status='Imported')
            if len(searchRes) == 1:
                extra.append(
                    (searchRes[0], [('%.2f' % x).zfill(5) for x in tup[1]]))
            else:
                total.append((tup[0], [('%.2f' % x).zfill(5) for x in tup[1]]))

    print('Create %s ...' % ('AllCredits_%s.txt' % sheetNr),
          end='',
          flush=True)
    writeNameCreditLists(path, 'AllCredits_%s.txt' % sheetNr, total)
    print('[OK]')

    extTutDict = {}
    for elem in extra:
        eTutor = elem[0]['ExtTut']
        if eTutor in extTutDict:
            extTutDict[eTutor].append((elem[0]['Name'], elem[1]))
        else:
            extTutDict[eTutor] = [(elem[0]['Name'], elem[1])]

    for k, v in extTutDict.items():
        fname = 'AllCredits_%s_%s_%s.txt' % (sheetNr, fm.getTFirstName(),
                                             k.replace(' ', '-'))
        print('Create %s ...' % fname, end='', flush=True)
        writeNameCreditLists(path, fname, v)
        print('[OK]')
Exemple #4
0
 def links(self):
     debug(self._label + "create additional symlinks")
     src_install = pjoin(Settings.CONTROL_PATH, self._package["package"] + ".links")
     if not pexists(src_install):
         return
     try:
         lineno = 0
         with open(src_install) as fin:
             for line in fin:
                 lineno += 1
                 src, dst = line.strip().split(" ", 1)
                 dst = dst.strip()
                 if dst.startswith("/"):
                     dst = "." + dst
                 dst = pjoin(self._env["QPKG_DEST_DATA"], dst)
                 if dst.endswith("/"):
                     if not pexists(dst):
                         makedirs(dst)
                     dst = pjoin(dst, pbasename(src))
                 else:
                     if not pexists(pdirname(dst)):
                         makedirs(pdirname(dst))
                 symlink(src, dst)
     except ValueError:
         raise FileSyntaxError(src_install, lineno, line)
Exemple #5
0
    def run(self, **kargs):
        # Act as QDK1
        if self._args.qdk1:
            # TODO: build as qdk1 flow
            q = self._args.qpkg_dir
            result = QbuildToQpkg(q).build(self)
            info('Package is ready in ' + result)
            return 0

        if self.qpkg_dir is None:
            error('Cannot find QNAP/control anywhere!')
            error('Are you in the source code tree?')
            return -1

        # Act as QDK2
        try:
            qbuild_formats = Qdk2ToQbuild(self).transform()
            for q in qbuild_formats:
                debug(q)
                result = QbuildToQpkg(q).build(self)
                arch = q[q.rfind('_'):]
                dest = pjoin(self.build_dir,
                             pbasename(result)[:-5] + arch + '.qpkg')
                move(result, dest)
                info('Package is ready: ' + dest)
        except BaseStringException as e:
            error(str(e))
            return -1
        return 0
def uploadExternalCreditFile(eCreditFile, fm):
    print('Upload %s to MÜSLI.' % eCreditFile)
    sheetNr = extractSheetNr(eCreditFile)
    eTut = pbasename(eCreditFile).split('.')[0].split('_')[3].replace('-', ' ')
    print(eTut)
    names = getAllStudentNames(eCreditFile)

    with MuesliApi(acc=fm.getMÜSLIAcc()) as mapi:
        tids = fm.getETIDs()
        infos = [
            info for info in fm.getETutMetaInfo() if info['ExtTut'] == eTut
        ]

        for tid in tids:
            for info in infos:
                if len(names) == 0:
                    print('Nothing to match!')
                    return

                if tid == info['ID']:
                    print(info)
                    result, students = mapi.uploadCredits(
                        info, eCreditFile, sheetNr)

                    print()

                    print('Matched: ')
                    for r, k in result.items():
                        names.remove(r)
                        print(r, k)
                    print('Still need to match:')
                    for name in names:
                        print(name)
Exemple #7
0
 def links(self):
     debug(self._label + 'create additional symlinks')
     src_install = pjoin(Settings.CONTROL_PATH,
                         self._package['package'] + '.links')
     if not pexists(src_install):
         return
     try:
         lineno = 0
         with open(src_install) as fin:
             for line in fin:
                 lineno += 1
                 src, dst = line.strip().split(' ', 1)
                 dst = dst.strip()
                 if dst.startswith('/'):
                     dst = '.' + dst
                 dst = pjoin(self._env['QPKG_DEST_DATA'], dst)
                 if dst.endswith('/'):
                     if not pexists(dst):
                         makedirs(dst)
                     dst = pjoin(dst, pbasename(src))
                 else:
                     if not pexists(pdirname(dst)):
                         makedirs(pdirname(dst))
                 symlink(src, dst)
     except ValueError:
         raise FileSyntaxError(src_install, lineno, line)
def do_generate_interface(target, source, env):
    """Generate a .pyf file from another pyf file (!)."""
    # XXX: do this correctly
    target_name = str(target[0])
    source_name = str(source[0])

    # XXX handle skip names
    name = splitext(pbasename(target_name))[0]
    generate_interface(name, source_name, target_name)
    return 0
Exemple #9
0
def do_generate_interface(target, source, env):
    """Generate a .pyf file from another pyf file (!)."""
    # XXX: do this correctly
    target_name = str(target[0])
    source_name = str(source[0])

    # XXX handle skip names
    name = splitext(pbasename(target_name))[0]
    generate_interface(name, source_name, target_name)
    return 0
Exemple #10
0
    def _import_container(self, container, directory):
        ctype, cid = self._args.container
        container = Container()

        info('Copy container (switch to root)')
        if ctype == 'lxc':
            container.import_lxc(cid, self.directory)
        elif ctype == 'docker':
            container.import_docker(cid, self.directory)
        else:
            raise ContainerUnsupported(str(self._args.container))

        # cook container.json
        tpl_vars = [('@@IMAGE_ID@@', cid),
                    ('@@NAME@@', self._args.project),
                    ('@@TYPE@@', ctype)]
        src = pjoin(Settings.TEMPLATE_PATH, 'container', 'container.json')
        dst = pjoin(self.directory, 'container.json')
        with open(src, 'r') as fin, open(dst, 'w') as fout:
            for line in fin:
                for k, v in tpl_vars:
                    line = line.replace(k, v)
                fout.write(line)
        # cook QNAP control files
        makedirs(pjoin(self._directory, Settings.CONTROL_PATH))
        tpl_files = glob(pjoin(Settings.TEMPLATE_PATH, 'container',
                               Settings.CONTROL_PATH, '*'))
        for tpl in tpl_files:
            fn = pbasename(tpl)
            if fn.find('.') == -1:
                dst = pjoin(self._directory, Settings.CONTROL_PATH, fn)
            else:
                dst = pjoin(self._directory, Settings.CONTROL_PATH,
                            self._args.project + fn[fn.index('.'):])
            with open(tpl, 'r') as fin, open(dst, 'w') as fout:
                for line in fin:
                    line = line.replace('@@PACKAGE@@', self._args.project)
                    fout.write(line)
                if pbasename(dst) != 'control':
                    chmod(dst, 0755)
        return 0
Exemple #11
0
def generate_api_emitter(target, source, env):
    """Returns the list of targets generated by the code generator for array
    api and ufunc api."""
    base, ext = split_ext(str(target[0]))
    dir = pdirname(base)
    ba = pbasename(base)
    h = pjoin(dir, "__" + ba + ".h")
    c = pjoin(dir, "__" + ba + ".c")
    txt = base + ".txt"
    # print h, c, txt
    t = [h, c, txt]
    return (t, source)
Exemple #12
0
def generate_api_emitter(target, source, env):
    """Returns the list of targets generated by the code generator for array
    api and ufunc api."""
    base, ext = split_ext(str(target[0]))
    dir = pdirname(base)
    ba = pbasename(base)
    h = pjoin(dir, '__' + ba + '.h')
    c = pjoin(dir, '__' + ba + '.c')
    txt = base + '.txt'
    #print h, c, txt
    t = [h, c, txt]
    return (t, source)
Exemple #13
0
 def extract_image(self, image, to):
     with create_temp_direcory() as d:
         check_call(['tar', 'xf', Settings.QPKG, '-C', d])
         tools_base = glob(pjoin(d, 'qpkg_*'))[0]
         extractor = pjoin(tools_base, 'PC1')
         info('Copy image to working area... ' + d)
         copy(image, pjoin(tools_base, 'cde-root'))
         info('Decrypting...')
         check_call([extractor, 'd', 'QNAPNASVERSION4', pbasename(image),
                     '/a.tgz'])
         info('Extracting...')
         check_call(['tar', 'xvf', pjoin(tools_base, 'cde-root', 'a.tgz'),
                     '-C', to])
def get_physical_nics():
    options = []
    bonds = {}
    for p in glob('/sys/class/net/eth*'):
        options.append(pbasename(p))
    options = set(options)
    for p in glob('/sys/class/net/bond*'):
        eths = []
        for psub in glob(p + '/lower_*') + glob(p + '/brif/*'):
            psub = pbasename(psub)
            if psub.startswith('lower_'):
                psub = psub[6:]
            if not psub.startswith('eth'):
                continue
            eths.append(psub)
            options -= {psub}
        if len(eths) > 0:
            options.add('+'.join(eths))
            bonds[pbasename(p)] = '+'.join(eths)
    options = list(options)
    options.sort()
    return options
def get_physical_nics():
    options = []
    bonds = {}
    for p in glob('/sys/class/net/eth*'):
        options.append(pbasename(p))
    options = set(options)
    for p in glob('/sys/class/net/bond*'):
        eths = []
        for psub in glob(p + '/lower_*') + glob(p + '/brif/*'):
            psub = pbasename(psub)
            if psub.startswith('lower_'):
                psub = psub[6:]
            if not psub.startswith('eth'):
                continue
            eths.append(psub)
            options -= {psub}
        if len(eths) > 0:
            options.add('+'.join(eths))
            bonds[pbasename(p)] = '+'.join(eths)
    options = list(options)
    options.sort()
    return options
Exemple #16
0
 def format_qdk1(self):
     info('The template are putting to ' + self.directory)
     if pexists(self.directory):
         yn = raw_input('{} folder exists! Confirm? [Y/n] '.format(
             self.directory))
         if len(yn) and yn[0].lower() == 'n':
             raise UserExit()
     else:
         makedirs(self.directory)
     for fn in glob(pjoin(Settings.TEMPLATE_V1_PATH, '*')):
         dest = pjoin(self.directory, pbasename(fn))
         if isdir(fn):
             copytree(fn, dest, True)
         else:
             copy(fn, dest)
Exemple #17
0
 def format_qdk1(self):
     info('The template are putting to ' + self.directory)
     if pexists(self.directory):
         yn = raw_input('{} folder exists! Confirm? [Y/n] '.format(
                        self.directory))
         if len(yn) and yn[0].lower() == 'n':
             raise UserExit()
     else:
         makedirs(self.directory)
     for fn in glob(pjoin(Settings.TEMPLATE_V1_PATH, '*')):
         dest = pjoin(self.directory, pbasename(fn))
         if isdir(fn):
             copytree(fn, dest, True)
         else:
             copy(fn, dest)
def main():
    # Read and Save the Original Input File to Work From
    with open(input_file_og, 'r') as ipf_og:
        for idx, line in enumerate(ipf_og.readlines()):
            line_text.append(line.strip())

    # Make and Write a Modified Input File
    input_file_mod = pjoin(
        pdirname(input_file_og),
        os.path.splitext(pbasename(input_file_og))[0] + '_cbrain.txt')
    #input_file_mod = pjoin(pdirname(input_file_og),pbasename(input_file_og) + '_cbrain.txt')
    with open(input_file_mod, 'w+') as ipf_mod:
        for idx in range(len(line_text)):
            mod_line_text = line_text[idx].replace(
                "/CBRAIN_PROCESSING_LOCATION", real_cbrain_path)
            ipf_mod.write(mod_line_text + "\n")
Exemple #19
0
 def extract_image(self, image, to):
     with create_temp_direcory() as d:
         check_call(['tar', 'xf', Settings.QPKG, '-C', d])
         tools_base = glob(pjoin(d, 'qpkg_*'))[0]
         extractor = pjoin(tools_base, 'PC1')
         info('Copy image to working area... ' + d)
         copy(image, pjoin(tools_base, 'cde-root'))
         info('Decrypting...')
         check_call([
             extractor, 'd', 'QNAPNASVERSION4',
             pbasename(image), '/a.tgz'
         ])
         info('Extracting...')
         check_call([
             'tar', 'xvf',
             pjoin(tools_base, 'cde-root', 'a.tgz'), '-C', to
         ])
Exemple #20
0
def do_generate_fake_interface(target, source, env):
    """Generate a (fake) .pyf file from another pyf file (!)."""
    # XXX: do this correctly
    target_name = str(target[0])
    source_name = str(source[0])

    # XXX handle skip names
    name = splitext(pbasename(target_name))[0]
    #generate_interface(name, source_name, target_name)

    f = open(target_name, 'w')
    f.write('python module '+name+'\n')
    f.write('usercode void empty_module(void) {}\n')
    f.write('interface\n')
    f.write('subroutine empty_module()\n')
    f.write('intent(c) empty_module\n')
    f.write('end subroutine empty_module\n')
    f.write('end interface\nend python module'+name+'\n')
    f.close()

    return 0
Exemple #21
0
def sendFeedbackMails(wpath, sendable=False):
    fm = FolderManager(wpath)
    #print(os.path.basename(os.path.dirname(wpath)))
    sheetNr = pbasename(pdirname(wpath)).split('_')[1]

    studs = fm.getAllStudents(status='Local;Imported')
    mailHtmlDict = prepareMails(studs, fm.getMyEmailData(), wpath,
                                fm.getReturnTemplatePath())

    if sendable:
        quest = 'Do u rly want to send Feedbackmails to ur students? (Y|n)'
        sendable = input(quest) == 'Y'
    else:
        print(
            'Mails prepared. To send it after prepareing use -S as console parameter'
        )

    if sendable:
        with Sender(acc=fm.getMailAcc()) as sender:
            sender.allowed = sendable
            sender.sendFeedbackMails(fm.getSubject(), sheetNr, mailHtmlDict)
def do_generate_fake_interface(target, source, env):
    """Generate a (fake) .pyf file from another pyf file (!)."""
    # XXX: do this correctly
    target_name = str(target[0])
    source_name = str(source[0])

    # XXX handle skip names
    name = splitext(pbasename(target_name))[0]
    generate_interface(name, source_name, target_name)

    f = open(target_name, 'w')
    f.write('python module '+name+'\n')
    f.write('usercode void empty_module(void) {}\n')
    f.write('interface\n')
    f.write('subroutine empty_module()\n')
    f.write('intent(c) empty_module\n')
    f.write('end subroutine empty_module\n')
    f.write('end interface\nend python module'+name+'\n')
    f.close()

    return 0
Exemple #23
0
def mangle_fortranobject(targetname, filename):
    basename = pbasename(targetname).split('module')[0]
    return '%s_%s' % (basename, filename)
def generate_from_template_emitter(target, source, env):
    """Scons emitter for both C and Fortran generated files from template (.src
    files)."""
    base = splitext(pbasename(str(source[0])))[0]
    t = pjoin(pdirname(str(target[0])), base)
    return ([t], source)
def generate_from_template_emitter(target, source, env):
    """Scons emitter for both C and Fortran generated files from template (.src
    files)."""
    base = splitext(pbasename(str(source[0])))[0]
    t = pjoin(pdirname(str(target[0])), base)
    return ([t], source)
def extractSheetNr(fName):
    return int(pbasename(fName).split('.')[0].split('_')[1])
def get_nic_parent(nic):
    bridge_path = glob('/sys/class/net/' + nic + '/brport/bridge')
    if len(bridge_path) <= 0:
        return None
    bridge_name = pbasename(readlink(bridge_path[0]))
    return bridge_name
Exemple #28
0
def generate_from_template_emitter(target, source, env):
    base, ext = split_ext(pbasename(str(source[0])))
    t = pjoin(pdirname(str(target[0])), base)
    return ([t], source)
Exemple #29
0
def createGlobalMetaData(root=getcwd()):
    globalMdataPath = pjoin(root, 'GlobalMetaData')
    onChange = False

    if not pexists(globalMdataPath):
        print('GlobalMetaData', globalMdataPath)
        omakedirs(globalMdataPath)
    else:
        print('[WARNING] GlobalMetaData folder already exists!')
        if input('Wanna override and recreate files (step by step)? (Y|n)'
                 ) != 'Y':
            print('Execution terminated...')
            return globalMdataPath

    tutLinks = None

    #MetaData.txt
    #--------------------------------------------------------------------------
    metaDataFile = getMetaDataPath(globalMdataPath)
    if pexists(metaDataFile):
        inp = input('MetaData are already existent: \n\
                     o|O Override \n\
                     m|M Modify   \n\
                     .*  Skip\n\nChoose option: ')
        if inp.lower() == 'o':
            tutLinks = createMetaDataFile(globalMdataPath)
            onChange = True

        elif inp.lower() == 'm':
            tutLinks = modifyMetaData(globalMdataPath)
            onChange = True

        else:
            print('MetaData.txt will not be changed.')

    else:
        print('Create %s' % pbasename(metaDataFile))
        tutLinks = createMetaDataFile(globalMdataPath)

    if tutLinks == None:
        tutLinks = getTutMetaInfo(globalMdataPath)

    #<ID>_MuesliData.txt
    #--------------------------------------------------------------------------
    for tut in tutLinks:
        tutpath = pjoin(globalMdataPath, tut['ID'] + '_MuesliData.txt')

        if not pexists(tutpath):
            createTutoriumList(tutpath, tut)
        else:
            if input('Do u want to sync and override data for (%s %s)? (Y|n)' %
                     (tut['Day'], tut['Time'])) == 'Y':
                print('Synced')
                print(tutpath, tut)
                createTutoriumList(tutpath, tut)
                onChange = True
            else:
                print('Skipped')

    studentsListPath = pjoin(globalMdataPath, 'StudentList.txt')
    #External
    createExternalStudentsList(globalMdataPath)

    # Pre-Init
    if not pexists(studentsListPath):
        createStudentsList(globalMdataPath, ignore=True)

    #Imported/Exported
    print('=' * 30)
    importPath = pjoin(globalMdataPath, 'Imported.txt')
    print('=' * 30)
    exportPath = pjoin(globalMdataPath, 'Exported.txt')

    cif = createImportFile(importPath)
    cef = createExportFile(exportPath)
    onChange = cif or cef or onChange

    if onChange:
        print('Some files have been updated - Updating StudentsList')

    if not pexists(studentsListPath) or onChange:
        createStudentsList(globalMdataPath)
    else:
        print('There were no changes on student data.')
        if input('Do u want to update \'%s\' anyways? (Y|n)' %
                 pbasename(studentsListPath)) == 'Y':
            createStudentsList(globalMdataPath)
        else:
            print('Skipped')

    print('GlobalMetaData created and ready to be used')
    return globalMdataPath
Exemple #30
0
def prepareMails(studs, me, wPath, template):
    gFeedback = None
    maxCreds = []
    result = {}
    me = {'Name': me[0], 'Mail': me[1]}

    for root, dirs, files in owalk(wPath):
        if 'GlobalFeedback.txt' in files:
            gFeedback = pjoin(root, 'GlobalFeedback.txt')
            maxCreds = getMaxCredits(pjoin(root, 'MaxCredits.txt'))

        if 'Feedback.txt' in files:
            #print(root, dirs, files)
            pathElems = splitpath(root)
            students = [
                x.split('(')[0].replace('-', ' ')
                for x in pbasename(root).split('_')[2:]
            ]
            creds = extractCredits(pjoin(root, 'credits.txt'))
            creds = [creds[i] + maxC for i, maxC in enumerate(maxCreds)]
            sheetNr = int(pathElems[-4].split('_')[1])
            paths = {
                'Feedback': pjoin(root, 'Feedback.txt'),
                'Global': gFeedback
            }

            htmlPath = createReturnMailFromTemplate(me,
                                                    students,
                                                    creds,
                                                    template,
                                                    sheetNr,
                                                    paths,
                                                    retPath=True)

            for name in students:
                for stud in studs:
                    if cmpNameParts(stud['Name'].split(' '), name.split(' ')):
                        studs.remove(stud)
                        result[stud['Mail']] = htmlPath
                        break
                    else:
                        replacer = {
                            'ä': 'ae',
                            'ü': 'ue',
                            'ö': 'oe',
                            'Ü': 'Ue',
                            'Ö': 'Oe',
                            'Ä': 'Ae',
                            'ß': 'ss'
                        }

                        #org = stud['Name']
                        tmp = stud['Name']
                        for k, v in replacer.items():
                            tmp = tmp.replace(k, v)

                        if cmpNameParts(tmp.split(' '), name.split(' ')):
                            studs.remove(stud)
                            result[stud['Mail']] = htmlPath
                            break

    for s in studs:
        result[s['Mail']] = createDefaultReturnMailFromTemplate(
            me,
            s['Name'],
            template,
            sheetNr,
            gFeedback,
            resultFilename=None,
            retPath=True)

    return result
Exemple #31
0
def generate_from_template_emitter(target, source, env):
    base, ext = split_ext(pbasename(str(source[0])))
    t = pjoin(pdirname(str(target[0])), base)
    return ([t], source)
Exemple #32
0
def mangle_fortranobject(targetname, filename):
    basename = pbasename(targetname).split('module')[0]
    return '%s_%s' % (basename, filename)
Exemple #33
0
def main():

    # Set Up

    checkscript, ext = psplit(pbasename(checkscript_ver))
    os.chdir(version_check_location)
    summary_file = pjoin(version_check_location,
                         "Mass_Verification_Summary.txt")

    # Main Caller
    # Crawl through folders starting at base searching for matlab and octave results to verify
    matlabfile = ""
    octavefile = ""
    for option in os.listdir(version_check_location):
        if os.path.isdir(pjoin(version_check_location, option)):
            for environment in os.listdir(pjoin(version_check_location,
                                                option)):
                input_txt_file_path = pjoin(version_check_location, option,
                                            environment)
                if os.path.isdir(input_txt_file_path):
                    print("Checking {} for OPPNI input files".format(
                        pjoin(version_check_location, option, environment)))
                    #                    for processed in os.listdir(pjoin(version_check_location, option, environment)):
                    #                        if os.path.isdir(pjoin(version_check_location,option,environment,processed)):
                    #                            input_txt_file_path = pjoin(version_check_location, option, environment, processed)

                    # Gets input files ready
                    if "matlab" in environment:
                        matlabfile = pjoin(input_txt_file_path,
                                           matlab_input_file_name)
                    if "octave" in environment:
                        octavefile = pjoin(input_txt_file_path,
                                           octave_input_file_name)


#                        pass
                    pass
                pass

                if matlabfile == "":
                    print("Unable to locate OPPNI Matlab input.txt: ",
                          input_txt_file_path)
                    continue
                if octavefile == "":
                    print("Unable to locate OPPNI Octave input.txt: ",
                          input_txt_file_path)
                    continue
            pass
            if matlabfile == "" or octavefile == "":
                print(
                    "Unable to locate file to varify, moving to next directory path"
                )
                continue

            # Get call ready
            # check for successful OPPNI completion (matlab)
            out_dir = os.path.dirname(os.path.abspath(matlabfile))
            fileList = glob.glob(
                pjoin(out_dir, "processing_input_file_*", "*.pkl"))
            out_dir = os.path.dirname(os.path.abspath(fileList[0]))
            print("Options file is: {}".format(fileList[0]))
            prev_proc_status, prev_options, prev_input_file_all, failed_sub_file, failed_spnorm_file, all_subjects = update_proc_status(
                out_dir)
            if not prev_proc_status.all_done:
                print(
                    'Previous processing is incomplete for:{} \n Moving on to next result set.'
                    .format(matlabfile))
                continue
            else:
                print("matlabfile = ", matlabfile)

            #check for successful OPPNI completion (octave)
            out_dir = os.path.dirname(os.path.abspath(octavefile))
            fileList = glob.glob(
                pjoin(out_dir, "processing_input_file_*", "*.pkl"))
            out_dir = os.path.dirname(os.path.abspath(fileList[0]))
            print("Options file is: {}".format(fileList[0]))
            prev_proc_status, prev_options, prev_input_file_all, failed_sub_file, failed_spnorm_file, all_subjects = update_proc_status(
                out_dir)
            if not prev_proc_status.all_done:
                print(
                    'Previous processing is incomplete for:{} \n Moving on to next result set.'
                    .format(octavefile))
                continue
            else:
                print("octavefile = ", octavefile)

            savefile = pjoin(version_check_location, option,
                             "MvsO_results.txt")
            print("Results will be saved to: ", savefile)

            call_command = "addpath(genpath('" + matlab_path + "')); " + checkscript + "('" + matlabfile + "','" + octavefile + "','" + savefile + "'); exit;"

            print("validation command line: ", call_command)

            #Call matlab from command terminal to run Nathans Version Checker
            subprocess.call(
                ["matlab", "-nodesktop", "-nosplash", "-r", call_command])

            # Load file and check for all [OK]
            totalok = 0
            with open(savefile, 'r') as result:
                for idx, line in enumerate(result.readlines()):
                    if "[OK]" in line:
                        totalok += 1
            summary_string = "Verified " + str(
                totalok) + "/14 [OK] for: " + pbasename(pdirname(savefile))

            # Save results into summary
            with open(summary_file, 'w+') as summary:
                summary.write(summary_string)
        #if now process gets killed in between here we don't remove the old one
        new_influentials = {
            k: v
            for k, v in used_influentials.items()
            if k not in self.loaded_influentials
        }
        print((
            f"Saved under {name}. \n"
            f"  Took {timedelta(seconds=runtime)}. \n" +
            ((f"  New Influential Config: {new_influentials}. \n")
             if new_influentials else "") +
            ((f"  Saved Meta-Inf: {metainf}. \n") if metainf else "") +
            ((f"  New forbidden Config: {', '.join(self.ctx.forbidden_configs)}. \n"
              ) if self.ctx.forbidden_configs else "")).strip())
        #TODO telegram-send this string as well if telegram-functionality enabled
        if len((sp := splitext(pbasename(name))[0].split("_")
                )) >= 3 and sp[-2] == "INTERRUPTED" and int(sp[-1]) >= 2:
            warnings.warn(
                "!! This is saved under a name I won't find it again!!")
            raise FileNotFoundError(
                f"!! This is saved under a name I won't find it again: {basename(name)}"
            )
        return name

    def add_plot(self, title, data):
        self.created_plots[title] = json.dumps(data, cls=NumpyEncoder)

    def collected_metainf(self):
        per_file = {
            k: v.get("metadata", {}).get("metainf", {})
            for k, v in self.loaded_objects.items()
Exemple #35
0
def main(oppni_ver, input_file_og, pipeline_file, reference_file):
    # Read and Save the Original Input File to Work From
    with open(input_file_og, 'r') as ipf_og:
        for idx, line in enumerate(ipf_og.readlines()):
            line_text.append(line.strip())
            out_text.append(get_out_dir_line(line))
    base_out_dir = pdirname(out_text[0])

    # Main Loop : Apply Conditions
    for model in CODES_ANALYSIS_MODELS:
        for pattern in SLICE_TIMING_PATTERNS:
            for dflag in DEOBLIQUE:

                # Generate Suffix
                suffix = "Opt_" + str(model) + '_' + str(pattern) + '_' + str(
                    dflag)

                # 2 Execution Methods
                for env in EXE_METHODS:

                    # Create New Folders
                    base_cond_dir = pjoin(base_out_dir, suffix)
                    base_cond_env_dir = pjoin(base_cond_dir, str(env))

                    os.makedirs(base_cond_dir, exist_ok=True)
                    os.makedirs(base_cond_env_dir, exist_ok=True)

                    # Make and Write a Modified Input File
                    input_file_mod = pjoin(base_cond_env_dir, 'input_file.txt')
                    with open(input_file_mod, 'w+') as ipf_mod:
                        for idx in range(len(line_text)):
                            # prepending it with OUT= to restrict the sub to only OUT, and not elsewhere such as TASK=
                            mod_out_text = 'OUT=' + pjoin(
                                pdirname(out_text[idx]), suffix, str(env),
                                pbasename(out_text[idx]))
                            #                            rep_text = 'OUT={}'.format(base_out_dir)
                            rep_text = 'OUT={}'.format(
                                pjoin(base_out_dir, pbasename(out_text[idx])))
                            mod_line_text = line_text[idx].replace(
                                rep_text, mod_out_text)

                            #out_text[idx] = 'OUT={}'.format(base_out_dir)
                            #mod_line_text = line_text[idx].replace(out_text[idx], mod_out_text)
                            print(
                                "rep_text = [{}]\nmod_out_text = [{}]\nmod_line_text = [{}]\n"
                                .format(rep_text, mod_out_text, mod_line_text))

                            #DEBUG
                            #if input("Continue? (Y)").upper() != "Y":
                            #    sys.exit()

                            ipf_mod.write(mod_line_text + "\n")

                    # Make and Write a Modified Command File
                    commandfile = pjoin(
                        pjoin(base_cond_env_dir,
                              "cmd_" + suffix + "_" + str(env) + '.sh'))
                    with open(commandfile, "w+") as cmd_fid:
                        submit_string = (
                            'python ' + oppni_ver + ' -i ' + input_file_mod +
                            ' -c ' + pipeline_file + ' -a ' + str(model) +
                            ' -r ' + reference_file + ' ' + volume +
                            ' --TPATTERN ' + str(pattern) + ' --convolve ' +
                            convolve + ' -m ' + metric + ' -e ' + str(env) +
                            ' ' + str(dflag) + ' ' + cluster + ' --contrast ' +
                            contrast + ' ' + vasc_mask + ' ' + blur + ' ' +
                            control_motion_artifact + ' ' + control_wm_bias +
                            ' ' + output_nii_also + ' ' + dry_run + ' ' +
                            run_locally)
                        cmd_fid.write(submit_string)

                    # Run OPPNI in Terminal
                    # Make Sure that System Settings are Correct
                    exit_code = os.system(
                        submit_string)  # TURN THIS ON AND OFF
                    if exit_code != 0:
                        print("\nExit Code {} was returned for command [{}]".
                              format(exit_code, submit_string))
                        if (input("\nContinue with next command? (Y/N):").
                                upper() == 'N'):
                            sys.exit()
Exemple #36
0
 def get_sample_list(self):
     samples = glob(pjoin(Settings.SAMPLES_PATH, '*.tar.gz'))
     samples = [pbasename(sample)[:-7] for sample in samples]
     return samples
def get_nic_parent(nic):
    bridge_path = glob('/sys/class/net/' + nic + '/brport/bridge')
    if len(bridge_path) <= 0:
        return None
    bridge_name = pbasename(readlink(bridge_path[0]))
    return bridge_name