Ejemplo n.º 1
0
 def remove(self, emptyOnly=False):
     """Smart remove.  Removes a file or directory tree, clearing the
        read-only flag if necessary.  If emptyOnly is True, then if path
        is a directory, only removes empty subdirectories and path if no
        files are present.  No files will be removed in this case.
        For standard Python file/directory remove functions, see:
           removefile, removedir, removedirs, removetree."""
     if os.path.exists(self._s):
         if os.path.isfile(self._s):
             try:
                 os.remove(self._s)
             except PermissionError:
                 os.chmod(self._s, stat.S_IWUSR | stat.S_IWOTH)
                 os.remove(self._s)
         elif emptyOnly:
             # Directory, recursively clean out empty directories
             roCleared = False
             for root, dirs, files in os.walk(self._s):
                 if not files and not dirs:
                     try:
                         os.removedirs(root)
                     except PermissionError:
                         if roCleared:
                             raise
                         self.setReadOnly(False)
                         roCleared = True
                         os.removedirs(root)
             # os.removedirs may have removed parent directories though, so
             # restore those if needed, but keep this directory deleted
             if not os.path.exists(self._s):
                 os.makedirs(self._s)
                 os.removedir(self._s)
         else:
             # Directory, recursively remove everything
             shutil.rmtree(self._s, onerror=_onerror)
Ejemplo n.º 2
0
    def install(self):
        self.targetDir = self.path.get()
        pre, post = os.path.split(self.targetDir)
        if not "emzed" in post.lower():
            msg = "Your install path looks suspicous.\n"
            msg += "Are you shure you want to install to\n%s\n????" % self.targetDir
            if not tkMessageBox.askyesno("Install path ok ?", msg):
                return

        try:
            testPath = os.path.join(self.targetDir, "TESTPATH")
            try:
                # cleanup from leftoverso of other installs
                os.removedirs(testPath)
            except:
                pass
            print "create", testPath
            os.makedirs(testPath)
            try:
                # cleanup from leftoverso of other installs
                print "cleanup", testPath
                os.removedir(testPath)
            except:
                pass
        except BaseException, e:
            tkMessageBox.showwarning(
                "Target", "could not create folder in" + self.targetDir)
            return
Ejemplo n.º 3
0
    def install(self):
        self.targetDir = self.path.get()
        pre, post = os.path.split(self.targetDir)
        if not "emzed" in post.lower():
            msg = "Your install path looks suspicous.\n"
            msg += "Are you shure you want to install to\n%s\n????" % self.targetDir
            if not tkMessageBox.askyesno("Install path ok ?", msg):
                return

        try:
            testPath = os.path.join(self.targetDir, "TESTPATH")
            try:
                # cleanup from leftoverso of other installs
                os.removedirs(testPath)
            except:
                pass
            print "create", testPath
            os.makedirs(testPath)
            try:
                # cleanup from leftoverso of other installs
                print "cleanup", testPath
                os.removedir(testPath)
            except:
                pass
        except BaseException, e:
            tkMessageBox.showwarning("Target", "could not create folder in"+self.targetDir)
            return
Ejemplo n.º 4
0
def clean():
    print current_time() + ' Cleaning'

    dest = distrib_dir
    assert (dest != '')
    assert (dest != source_dir)
    os.removedir(dest)

    dest = data_distrib_dir
    assert (dest != '')
    assert (dest != source_dir)
    os.removedir(dest)

    print current_time() + ' Done cleaning'
Ejemplo n.º 5
0
def clean():
    print current_time() + ' Cleaning'

    dest = distrib_dir
    assert(dest != '')
    assert(dest != source_dir)
    os.removedir(dest)

    dest = data_distrib_dir
    assert(dest != '')
    assert(dest != source_dir)
    os.removedir(dest)

    print current_time() + ' Done cleaning'
Ejemplo n.º 6
0
    def run_simulation(self):
        '''
        '''
        print "\nMODELSIM Run Simulation"

        ## switch into the simulation directory, this is why we added another layer to the root variable
        os.chdir(self.sim_dir)
        
        ##
        ## Get the machine type, 64 and 32 bit machine use different libraries
        ##
        stdout_handle = os.popen("uname -m", "r")
        machine =  stdout_handle.read().rstrip('\n')
        if machine == "x86_64":
            lin = "lin64"
        else:
            lin = "lin"

        vlog = self.get_executable("vlog")
        vsim = self.get_executable("vsim")
        vlib = self.get_executable("vlib")
        print "PATH: " + vlog
        print "PATH: " + vsim
        print "PATH: " + vlib

        switch_string = ""
        for i in self.switch:
            switch_string += " +define+"+str(i).strip("[']")         
        print "MODELSIM SWITCHES: " + switch_string

        if os.path.exists("work"):
            os.removedir("work")        

        command = vsim
        if not self.opts.gui:
            command += " -c "
            
        command += " -do simulation_file_list -l "+self.sim_log

            
        os.system(command)

           
        ## go back up to the level we started at
        os.chdir("..")

        
        return
input_eval_dir = "images"
# Checkout an OpenMVG image dataset with Git

cur_dir = os.getcwd()
img_filepath = cur_dir + os.sep + input_eval_dir + os.sep
image_filepath = img_filepath + os.listdir(img_filepath)[0]
im = Image.open(image_filepath)

focal_length = 1.2 * max(im.size)
focal_length_str = str(focal_length)

print("Focal:", focal_length_str)

output_eval_dir = "reconstructions"
try:
    os.removedir(output_eval_dir)
except:
    pass
if not os.path.exists(output_eval_dir):
    os.mkdir(output_eval_dir)
if not os.path.exists(output_images):
    os.mkdir(output_images)

input_dir = input_eval_dir
output_dir = output_eval_dir
print("Using input dir  : ", input_dir)
print("      output_dir : ", output_dir)

matches_dir = os.path.join(output_dir, "matches")
camera_file_params = os.path.join(CAMERA_SENSOR_WIDTH_DIRECTORY,
                                  "sensor_width_camera_database.txt")
'''
cwd = os.getcwd()
print(cwd)
'''
得到当前文件夹下的所有文件和文件夹
'''
print(os.listdir())
'''
delete file
'''
os.remove('sw724.vaps')
print(os.listdir())
'''
删除单个目录和多个目录
'''
os.removedir()
os.removedir()
'''
检查是否是文件/文件夹
'''
print(os.path.isfile('/Users/liuxiaolong/PycharmProjects/untitled/sw724.vaps'))
print(os.path.isdir('/Users/liuxiaolong/PycharmProjects/untitled/sw724.vaps'))
'''
检查文件路径是否存在
'''

print(os.path.exists('/Users/liuxiaolong/PycharmProjects/untitled/iiii'))
'''
分离文件名
分离扩展名
Ejemplo n.º 9
0
            for sd in subdirs:
                fullSdName = "%s/%s" % (directory, sd)
                for sdRoot, sdDirs, sdFiles in os.walk(fullSdName,
                                                       topdown=False):
                    for f in sdFiles:
                        try:
                            os.remove(f)
                            logme("INFO: File %s has been removed", f)
                        except Exception as e:
                            logme(
                                "ERROR: Problem deleting file: [Errno %d] %s, '%s'",
                                e.errno, e.strerror, e.filename)

                    try:
                        os.removedir(sdRoot)
                        logme("INFO: File %s has been removed", sdRoot)
                    except Exception as e:
                        logme(
                            "ERROR: Problem deleting directory: [Errno %d] %s, '%s'",
                            e.errno, e.strerror, e.filename)

            for f in files:
                if re.match(
                        r"(DQM|Playback|Playback_full)_V[0-9]{4}_([a-zA-Z]+)_R([0-9]{9})_T[0-9]{8}\.root",
                        f):
                    continue

                if re.match(r".*\.tmp", f):
                    continue
Ejemplo n.º 10
0
   logme("ERROR: Output directory %s, must not contain"
         " subdirectories, cleanning", COLLECTDIR)
   
 for sd in subdirs:
   fullSdName="%s/%s" % (directory,sd)
   for sdRoot,sdDirs,sdFiles in os.walk(fullSdName,topdown=False):
     for f in sdFiles:
       try:
         os.remove(f)
         logme("INFO: File %s has been removed", f)
       except Exception as e:
         logme("ERROR: Problem deleting file: [Errno %d] %s, '%s'",
                 e.errno, e.strerror, e.filename)
         
     try:
       os.removedir(sdRoot)
       logme("INFO: File %s has been removed" , sdRoot)
     except Exception as e:
       logme("ERROR: Problem deleting directory: [Errno %d] %s, '%s'",
                 e.errno, e.strerror, e.filename)
                 
 for f in files:
   if re.match(r"(DQM|Playback|Playback_full)_V[0-9]{4}_([a-zA-Z]+)_R([0-9]{9})_T[0-9]{8}\.root", f):
     continue
     
   if re.match(r".*\.tmp",f):
     continue
     
   fullFName="%s/%s" % (directory, f)
   FILE_LIST.append(fullFName)
   
Ejemplo n.º 11
0
from PIL import Image, ImageTk

init = Tkinter.Tk()
dirname = tkFileDialog.askdirectory(parent=init, initialdir = "C:\\Modelrun\\TruckModel\\RPi\\PiCount\\rampTrain\\pos", title = "Please Select Image Folder")

imageFiles = os.listdir(dirname)
init.destroy()

outFile = "C:\\Modelrun\\TruckModel\\RPi\\PiCount\\rampTrain\\positive.dat"
if os.path.exists:
    if os.path.isfile(outFile):
        os.remove(outFile)
        of = open(outFile,"w")
        of.close()
else:
    os.removedir(outFile)

doneCnt = 0

for imageFile in imageFiles:
    progress = str(doneCnt) + " of " + str(len(imageFiles)) + " completed"
    root = Tkinter.Tk()
    canvas = Tkinter.Canvas(root, width = 640, height = 220)
    canvas.pack()
    photo = ImageTk.PhotoImage(master=canvas, image=Image.open(dirname + "/" + imageFile))
    canvas.create_image(0,0,anchor="nw", image=photo)

    global x1, y1
    x1 = 0
    y1 = 0
    x2 = 0
Ejemplo n.º 12
0
 def teadDown(self):
     os.remove(self.zip_name)
     os.removedir(self.tmp_dir)
Ejemplo n.º 13
0
 def teadDown(self):
     os.remove(self.zip_name)
     os.removedir(self.tmp_dir )