コード例 #1
0
ファイル: main.py プロジェクト: jrojer/solution_checker
    def SelectInputFile(self):

        fd = QtGui.QFileDialog(self)

        self.input_file_path = fd.getOpenFileName()

        if self.input_file_path == '' : return

        if self.isNot_TeX_File(self.input_file_path):
            self.ui.input_file_field.setText(RedText('> Error: Unsupported file format'))
            self.input_file_path = ''
            return

        self.ui.input_file_field.setText(self.input_file_path)
        
        print('> got input file path:',self.input_file_path)
        
        
        
        self.tex_filename = PureWindowsPath(self.input_file_path).name # Potential Error
        self.tex_filename = self.tex_filename[:-4]+'_results.tex'
        
        self.working_dir = str( PureWindowsPath(self.input_file_path).parents[0] )
        print('> working dir set to :', self.working_dir)
        print('> tex file name set to :', self.tex_filename)
コード例 #2
0
def test_replace_music_folder(tmp_path, pl):
    replacement = (PureWindowsPath(':/Users/testuser/Desktop/songs'),
                   Path('/pool/Media/Music'))
    expected = ("/pool/Media/Music/08 Moonscape.mp3\n"
                "/pool/Media/Music/08 Mountains.mp3\n"
                "/pool/Media/Music/09 Outlands.mp3\n"
                "/pool/Media/Music/10 Crush.mp3\n")
    if os.path.sep == '\\':
        expected = expected.replace('/', '\\')

    path = tmp_path / 'test'
    m3u.write(pl, path, replace=replacement)
    assert path.read_text() == expected
コード例 #3
0
def files_in_dir(root_dir):
    """
    A function to get the full file paths for all files in root_dir
    """
    file_set = set()

    for dir_, _, files in os.walk(root_dir):
        for file_name in files:
            rel_dir = os.path.relpath(dir_, root_dir)
            rel_file = os.path.join(rel_dir, file_name)
            file_set.add(rel_file)

    return [Path(PureWindowsPath(f)) for f in file_set]
コード例 #4
0
 def find_func_dir(self, parent_tree=None, local_branch=None):
     conn_file_mat = loadmat(self.conn_file)
     func_dir_example = conn_file_mat["CONN_x"]["Setup"][0][0][0][0][6][0][
         0][0][0][0][0][0]
     if "\\" in func_dir_example:
         func_dir_example = PureWindowsPath(func_dir_example)
     else:
         func_dir_example = Path(func_dir_example)
     if not (parent_tree is None):
         self.func_dir = PurePath(local_branch) / sep.join(
             func_dir_example.parents[0].parts[parent_tree:])
     else:
         self.func_dir = func_dir_example.parents[0]
コード例 #5
0
def _compress(root_data_folder,
              command,
              flag_pattern,
              dry=False,
              max_sessions=None):
    #  runs a command of the form command = "ls -1 {file_name}.avi"
    c = 0
    for flag_file in Path(root_data_folder).rglob(flag_pattern):
        ses_path = flag_file.parent
        files2compress = flags.read_flag_file(flag_file)
        if isinstance(files2compress, bool):
            Path(flag_file).unlink()
            continue
        for f2c in files2compress:
            cfile = ses_path.joinpath(PureWindowsPath(f2c))
            c += 1
            if max_sessions and c > max_sessions:
                return
            print(cfile)
            if dry:
                continue
            if not cfile.exists():
                _logger.error(f'NON-EXISTING RAW FILE: {cfile}. Skipping...')
                continue
            if flag_file.exists():
                flag_file.unlink()
            # run the compression command redirecting output
            cfile.parent.joinpath(cfile.stem)
            # if the output file already exists, overwrite it
            outfile = cfile.parent / (cfile.stem + '.mp4')
            if outfile.exists():
                outfile.unlink()
            command2run = command.format(
                file_name=cfile.parent.joinpath(cfile.stem))
            process = subprocess.Popen(command2run,
                                       shell=True,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.PIPE)
            info, error = process.communicate()
            if process.returncode != 0:
                _logger.error('COMPRESSION FAILED FOR ' + str(cfile))
                with open(cfile.parent.joinpath('extract.error'), 'w+') as fid:
                    fid.write(command2run)
                    fid.write(error.decode())
            else:
                # if the command was successful delete the original file
                cfile.unlink()
                # and add the file to register_me.flag
                flags.write_flag_file(ses_path.joinpath('register_me.flag'),
                                      file_list=cfile.stem)
コード例 #6
0
def callFIJIstitch_noCompute(dir_in, dir_out, fiji_path):
    copyfile(src=Path(dir_out + 'TileConfiguration'
                                '.registered.txt'), dst=Path(dir_in + 'TileConfiguration.registered.txt'))
    copyfile(src=Path(dir_out + 'img_t1_z1_c1'), dst=Path(dir_out + 'img_t1_z1_c0'))

    script_file_p = dir_in + 'stitch_script_2.txt'
    dir_in = PureWindowsPath(dir_in).as_posix()
    dir_out = PureWindowsPath(dir_out).as_posix()
    out_file2 = open(script_file_p, 'w')
    out_file2.write('run("Grid/Collection stitching", "type=[Positions from file] order=[Defined by TileConfiguration] ' \
                    'directory={} layout_file=TileConfiguration.registered.txt ' \
                    'fusion_method=[Linear Blending] regression_threshold=0.30 max/avg_displacement_threshold=2.50 absolute_displacement_threshold=3.50 ' \
                    'computation_parameters=[Save computation time (but use more RAM)] image_output=[Write to disk] ' \
                    'output_directory={}");'
                    '\nrun("Quit");'
                    .format(dir_in,
                            dir_out))
    out_file2.close()
    base = os.path.splitext(script_file_p)[0]
    if os.path.exists(base + ".ijm"):
        os.remove(base + ".ijm")
    os.rename(script_file_p, base + ".ijm")
    call([fiji_path, '-macro', base + ".ijm"])
コード例 #7
0
def get_data_path(platform='reza_win'):
    if platform == 'reza_wsl':
        data_path = Path(
            '/mnt/c/Users/mamar/OneDrive - University of Toronto/Thesis/Brain Network/SPINS/SPINS_ciftify/schaefer_ea'
        )
    elif platform == 'reza_win':
        data_path = PureWindowsPath(
            r"C:\Users\mamar\OneDrive - University of Toronto\Thesis\Brain Network\SPINS\SPINS_ciftify\schaefer_ea"
        )
    elif platform == 'camh':
        data_path = Path('/projects/rebrahimi/GSP/SPINS_ciftify/schaefer_ea/')
    else:
        data_path = None
    return data_path
コード例 #8
0
def listDirFile(paths):
    listOfLocalFiles = {}  # List of dirs
    listOfMd5 = {}  # Key - Value pair of 'filename : md5sum'
    for index in paths:
        for dirpath, dirnames, filenames in os.walk(index):
            for file in filenames:
                full_path = os.path.join(dirpath, file)
                fullPathS3 = full_path.replace("\\", "/")
                listOfMd5[fullPathS3[len(index) + 1:]] = getFileMd5(full_path)
                if (full_path not in listOfLocalFiles):
                    fPath = Path(full_path)
                    listOfLocalFiles[PureWindowsPath(
                        fPath)] = fullPathS3[len(index) + 1:]
    return listOfLocalFiles, listOfMd5
コード例 #9
0
    def activate_item(self, e=None):
        tags_tree = self.tags_tree
        tree_id_to_index_ref = self.tree_id_to_index_ref
        if self.active_map is None or self.queue_tree is None:
            return
        elif ("halo2" in self.active_map.engine
              and self.active_map.engine != "halo2vista"):
            print("Cannot interact with Halo 2 Xbox maps.")
            return

        def_settings = {}
        if self.app_root:
            def_settings = dict(self.app_root.tk_vars)
            if self.app_root.running:
                return

        map_name = self.active_map.map_header.map_name
        # add selection to queue
        for iid in tags_tree.selection():
            if len(tags_tree.item(iid, 'values')):
                # tag_index_ref
                item_name = tags_tree.parent(iid) + tags_tree.item(iid, 'text')
                tag_index_ref = tree_id_to_index_ref[int(iid)]
                tag_index_refs = (tag_index_ref, )
            else:
                # directory
                item_name = iid
                tag_index_ref = None
                tag_index_refs = self._compile_list_of_selected(iid)

            # ask for extraction settings
            settings, original_name, title = self.show_actions_dialog(
                item_name, defaults=def_settings, tag_index_ref=tag_index_ref)

            if settings['accept_rename'].get():
                item_name = str(
                    PureWindowsPath(tags_tree.parent(iid),
                                    tags_tree.item(iid,
                                                   'text')).with_suffix(""))

                self.rename_tag_index_refs(tag_index_refs, original_name,
                                           settings['rename_string'].get(),
                                           settings['newtype_string'].get())
            elif settings['accept_settings'].get():
                settings['tag_index_refs'] = tag_index_refs
                settings['title'] = title
                self.queue_tree.add_to_queue(
                    "%s: map: %s: %s" %
                    (settings['extract_mode'].get(), map_name, item_name),
                    settings)
コード例 #10
0
def playback():
    # Get a random opening
    random_opening_name = getSelected()
    print(random_opening_name)
    # Retrieve the file it came from and find commands
    for filename in os.listdir(os.getcwd() + '\\files\\commands'):
        myfile = os.getcwd() + '\\files\\commands\\' + filename
        if ".json" in myfile:
            with open(myfile) as f:
                data = json.load(f)
                if data['Name'] == random_opening_name:
                    #command_file = Path("./files/commands/Temp.json")
                    #command_path = PureWindowsPath(command_file)
                    command_path = PureWindowsPath(myfile)
                    init(command_path)
コード例 #11
0
ファイル: main.py プロジェクト: jrojer/solution_checker
class Start(QtGui.QMainWindow):
    def __init__(self,parent=None):
        QtGui.QWidget.__init__(self,parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        QtCore.QObject.connect(self.ui.run_button,QtCore.SIGNAL("clicked()"),    self.Run )
        QtCore.QObject.connect(self.ui.about_button,QtCore.SIGNAL("clicked()"),    self.About )
        QtCore.QObject.connect(self.ui.select_input_button,QtCore.SIGNAL("clicked()"),    self.SelectInputFile )
        QtCore.QObject.connect(self.ui.select_pdflatex_button,QtCore.SIGNAL("clicked()"),    self.SelectPdflatexFile )

        self.input_file_path    = ''
        self.pdflatex_file_path = ''
        self.fo_tex = 0
        self.tex_file_path = ''
        self.tex_filename = ''
        self.working_dir = ''


    def AboutClose(self):
        self.about_widget.hide()

    def About(self):
        # A help window popups
        self.about_widget = QtGui.QWidget()  # create widget
        self.about = Ui_About() # get designer's code
        self.about.setupUi(self.about_widget) # apply designer's code
        QtCore.QObject.connect( self.about.OK_button,QtCore.SIGNAL("clicked()"),   self.AboutClose )
        self.about_widget.show()
    #

    def isNot_TeX_File(self,name): #check extension
        ending = name[-4:]
        if ending != '.tex':
            return True
        return False

    def SelectInputFile(self):

        fd = QtGui.QFileDialog(self)

        self.input_file_path = fd.getOpenFileName()

        if self.input_file_path == '' : return

        if self.isNot_TeX_File(self.input_file_path):
            self.ui.input_file_field.setText(RedText('> Error: Unsupported file format'))
            self.input_file_path = ''
            return

        self.ui.input_file_field.setText(self.input_file_path)
        
        print('> got input file path:',self.input_file_path)
        
        
        
        self.tex_filename = PureWindowsPath(self.input_file_path).name # Potential Error
        self.tex_filename = self.tex_filename[:-4]+'_results.tex'
        
        self.working_dir = str( PureWindowsPath(self.input_file_path).parents[0] )
        print('> working dir set to :', self.working_dir)
        print('> tex file name set to :', self.tex_filename)
        
        
    def isNotPdflatexFile(self,name):
        ending = name[len(name)-12:]
        if ending != 'pdflatex.exe' :
            return True
        return False

    def SelectPdflatexFile(self):

        fd = QtGui.QFileDialog(self)

        self.pdflatex_file_path = fd.getOpenFileName()
        
        print('> selected file:', self.pdflatex_file_path)
        

        if self.pdflatex_file_path == '' : return

        if self.isNotPdflatexFile(self.pdflatex_file_path):
            self.ui.pdflatex_field.setText(RedText('> Error: pdflatex.exe expected'))
            self.pdflatex_file_path = ''
            return

        self.ui.pdflatex_field.setText(self.pdflatex_file_path)

    def Print(self,text):
        print (text,file=self.fo_tex)
    def PPrint(self,expr):
        print ('\n$$\n',sympy.latex(expr),'\n$$\n',file=self.fo_tex)
        
    def InitiateTexFile(self):
                
        try:
            #cur_dir       = Path('.')
            cur_dir = Path(self.working_dir)
            #print('> current directory is set to: ',cur_dir)
            self.tex_file_path = str(cur_dir/self.tex_filename)
            self.fo_tex   = open(self.tex_file_path,'w') #TODO close ??
        except OSError:
            self.ui.input_file_field.setText(Redtext('.tex file cannot be created'))
            return True
        initial_string = '''
        
        \documentclass{article}
        \\usepackage[utf8]{inputenc}
        \\usepackage{amsthm}
        \\usepackage{amsmath}

        \\begin{document}

        '''
        #        \\usepackage[russian]{babel}
        self.Print(initial_string)
        print('> TeX file has been created')
        return False

    def RunPdflatexAndOpenPdf(self):
                
        print ('> Starting pdflatex.exe')
        args = [ self.pdflatex_file_path,
                '-interaction=batchmode',
                '-halt-on-error',
                '-no-shell-escape',
                self.tex_file_path
        ]
        tex_process = subprocess.call(args,cwd=self.working_dir)
        
        print('> pdflatex process return code : ', tex_process)
        
        (Path(self.working_dir)/(self.tex_filename[:-4]+'.log')).unlink()
        (Path(self.working_dir)/(self.tex_filename[:-4]+'.aux')).unlink()
        
        print ('> .aux and .log files deleted')
        
        print('> Openning pdf file...')
        pdf_filename = str ( Path(self.working_dir)/(self.tex_filename.replace('.tex','.pdf')) )
        import os
        os.system("start "+pdf_filename )

    def FilesArePresent(self):
        if self.isNotPdflatexFile(self.pdflatex_file_path):
            self.ui.pdflatex_field.setText(RedText('select file'))
            return False
        if self.isNot_TeX_File(self.input_file_path):
            self.ui.input_file_field.setText(RedText('select file'))
            return False
        return True
    def CheckODEs(self,fo):
        ''' read text file fo, solve ODEs, print results, close file '''
        funvar = FindFuncAndVar(fo)
        
        if  (funvar[0] == '' or funvar[1] == '') :
            self.ui.input_file_field.setText(RedText('ERROR: Function or Variable is not specified'))
            print('> ERROR: Function or Variable is not specified')
            return True
            
        print ('> function and variable defined')

        # reset fo
        fo.close()
        fo = open(self.input_file_path,'r')
        #
        print('> input file reopened')
        print('> Parsing input file ...')
        for i,data in enumerate(ParseTex(fo)):

            print('>> iteration :',i )
            print('>> data :',data)
            eqs  =  LatexToSympy(data+funvar)
            print('>> Checking solution ...')
            res  =  Check(eqs[0],eqs[1])

            self.Print('ODE number: '+str(i+1))
            self.PPrint(eqs[0])
            if res[0] == False :
                self.Print  ('Given solution:') 
                self.PPrint (eqs[1])
                self.Print  (' is INCORRECT') # RED letters
                self.Print  ('')
                self.Print  ('The correct one is:') 
                self.PPrint (res[1]) 
            else:
                self.Print('Solution:')
                self.PPrint(eqs[1])
                self.Print ('CORRECT') # GREEN letters
                self.Print ('')
            
        fo.close()
        return False
    '''        
    def ShowProcessingMessage(self):
        
        
        self.proc_mes = QtGui.QWidget()
        ui = Ui_Form()
        ui.setupUi(self.proc_mes)
        self.proc_mes.show()
    #
    def HideProcessingMessage(self):
        self.proc_mes.hide()
    '''        
    def VerifyInputFile(self):
      
        print('> Verifying input file...')
        args = [self.pdflatex_file_path,
        '-interaction=batchmode',
        '-halt-on-error',
        '-no-shell-escape',
        '-draftmode',
#        '-quiet',
        self.input_file_path
        ]

        tex_process = subprocess.call(args,cwd=self.working_dir)
        
        print('> pdflatex process return code : ', tex_process)
        
        Path(self.input_file_path[:-4]+'.aux').unlink()

        if tex_process != 0 :
            return True # error occured
        else:    
            Path(self.input_file_path[:-4]+'.log').unlink()
            
        return False # no error
        
    def Run(self):
	
        #self.ShowProcessingMessage()
		
        print ( '> RUNNING ...')
         
        if not self.FilesArePresent(): 
            print('> ERROR : select files')
            return
        
        
        error_occured = self.VerifyInputFile()
        if error_occured :
            print ('> ERROR: cannot compile the input file')
            self.ui.input_file_field.setText(RedText('ERROR: See .log file for details'))
            #TODO
            # ErrorMessage # look at log file
            return
            
            
        # open input file
        try:
            fo = open(self.input_file_path,'r')
        except (FileNotFoundError, NameError ) as e:
            self.ui.input_file_field.setText(RedText('cannot open file'))
            print('> ERROR: cannot open file')
            return
        #
        
        
        # initiate tex file	
        error_occured = self.InitiateTexFile()
        if error_occured :
            self.ui.input_file_field.setText(RedText('cannot create TeX file'))
            self.ui.pdflatex_field.setText(RedText('cannot create TeX file'))
            print('> ERROR: cannot create TeX file')
        #
       		
        error_occured = self.CheckODEs(fo) # fo will be closed there
        if error_occured :
            print ('> ODE checker ERROR')
            #TODO
            # ErrorMessage # look at log file
            return
        
        self.Print('\end{document}')
        self.fo_tex.close()
        
        print ('> Parsing finished')
        #self.HideProcessingMessage()
        self.RunPdflatexAndOpenPdf()
コード例 #12
0
ファイル: jiajiao.py プロジェクト: fhopecc/stxt
#文化局決算
from pathlib import Path, PureWindowsPath
from aisimporter import import_cba_csv

dir = PureWindowsPath("C:\\Users\\fhopecc\\Google 雲端硬碟\\家教中心決算\\dataset")
print(dir.as_posix())
print(dir / "cba.db")
import_cba_csv(str(dir.as_posix()),  str((dir / "cba.db").as_posix()))