python类removedirs()的实例源码

gtest.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 40 收藏 0 点赞 0 评论 0
def t05(w,h):
    pretty = '%s t5' % __file__
    print(pretty)

    result_path = w.make_tempdir()
    os.chmod(result_path, stat.S_IRUSR) # user read permission only
    try:
        h.run_gtest('some_target', result_path)
        print(
            'FAIL %s: expected error (not writable result directory): %s'
            % (pretty, temp_dir)
        )
        return False
    except Exception as e:
        if e.message != 'result_path not a writable directory: %s' % result_path:
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
    finally:
        os.removedirs(result_path)
    return True

# successful execution of run_gtest(): check files on host, verfiy their
#   content and that traces from run removed from handset
gtest.py 文件源码 项目:ave 作者: sonyxperiadev 项目源码 文件源码 阅读 47 收藏 0 点赞 0 评论 0
def t05(w,h):
    pretty = '%s t5' % __file__
    print(pretty)

    result_path = w.make_tempdir()
    os.chmod(result_path, stat.S_IRUSR) # user read permission only
    try:
        h.run_gtest('some_target', result_path)
        print(
            'FAIL %s: expected error (not writable result directory): %s'
            % (pretty, temp_dir)
        )
        return False
    except Exception as e:
        if e.message != 'result_path not a writable directory: %s' % result_path:
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            return False
    finally:
        os.removedirs(result_path)
    return True

# successful execution of run_gtest(): check files on host, verfiy their
#   content and that traces from run removed from handset
remove_stale_pyc_files.py 文件源码 项目:nojs 作者: chrisdickinson 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def RemoveAllStalePycFiles(base_dir):
  """Scan directories for old .pyc files without a .py file and delete them."""
  for dirname, _, filenames in os.walk(base_dir):
    if '.svn' in dirname or '.git' in dirname:
      continue
    for filename in filenames:
      root, ext = os.path.splitext(filename)
      if ext != '.pyc':
        continue

      pyc_path = os.path.join(dirname, filename)
      py_path = os.path.join(dirname, root + '.py')

      try:
        if not os.path.exists(py_path):
          os.remove(pyc_path)
      except OSError:
        # Wrap OS calls in try/except in case another process touched this file.
        pass

    try:
      os.removedirs(dirname)
    except OSError:
      # Wrap OS calls in try/except in case another process touched this dir.
      pass
test_vyper.py 文件源码 项目:vyper 作者: admiralobvious 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _init_dirs(self):
        test_dirs = ['a a', 'b', 'c\c', 'D_']
        config = 'improbable'

        root = tempfile.mkdtemp()

        def cleanup():
            try:
                os.removedirs(root)
            except (FileNotFoundError, OSError):
                pass

        os.chdir(root)

        for dir_ in test_dirs:
            os.mkdir(dir_, 0o0750)

            f = '{0}.toml'.format(config)
            flags = os.O_WRONLY | os.O_CREAT
            rel_path = '{0}/{1}'.format(dir_, f)
            abs_file_path = os.path.join(root, rel_path)
            with os.fdopen(os.open(abs_file_path, flags, 0o0640), 'w') as fp:
                fp.write("key = \"value is {0}\"\n".format(dir_))

        return root, config, cleanup
test_se.py 文件源码 项目:sudokuextract 作者: hbldh 项目源码 文件源码 阅读 63 收藏 0 点赞 0 评论 0
def test_se_tardata_sudokus(file_path_base):
    try:
        image_file_name = file_path_base + '.jpg'
        image = load_image(image_file_name)
    except:
        image_file_name = file_path_base + '.png'
        image = load_image(image_file_name)
    with open(file_path_base + '.txt', 'rt') as f:
        correct_parsing = f.read().strip()

    predictions, sudoku, subimage = extract_sudoku(image, classifier(), force=True)
    parsed_sudoku = predictions_to_suduko_string(predictions, oneliner=False)
    if parsed_sudoku != correct_parsing:
        predictions, sudoku, subimage = extract_sudoku(image.rotate(-90), classifier(), force=True)
        parsed_sudoku = predictions_to_suduko_string(predictions, oneliner=False)
    assert parsed_sudoku == correct_parsing


    try:
        os.remove(image_file_name)
        os.remove(file_path_base + '.txt')
        print("Deleted temporary test dir.")
        os.removedirs(os.path.dirname(file_path_base))
    except:
        pass
storage.py 文件源码 项目:sahriswiki 作者: prologic 项目源码 文件源码 阅读 82 收藏 0 点赞 0 评论 0
def delete_page(self, title, author=u'', comment=u''):
        """
        Remove empty directories after deleting a page.

        Note that Mercurial doesn't track directories, so we don't have to
        commit after removing empty directories.
        """

        super(WikiSubdirectoryStorage, self).delete_page(title, author, comment)
        file_path = self._file_path(title)
        self._check_path(file_path)
        dir_path = os.path.dirname(file_path)
        try:
            os.removedirs(dir_path)
        except OSError, e:
            pass # Ignore possibly OSError (39) Directory not empty errors.
DawnlightSearch_main.py 文件源码 项目:DawnlightSearch 作者: chg-hou 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def on_tableview_context_menu_delete(self):
        reply = QMessageBox.question(self, translate('message','Message'),
                                     translate('message',"Are you sure to DELETE?"), QMessageBox.Yes |
                                     QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            self.statusBar.showMessage(translate('statusbar',"Deleting..."))

            import shutil
            for Filename, Path, fullpath, IsFolder in self.get_tableview_selected():
                logger.info("Delete: " + fullpath)
                # if not os.path.exists(Path):    continue
                try:
                    if IsFolder:
                        os.removedirs(fullpath)
                    else:
                        os.remove(fullpath)
                except:
                    logger.error("Fail to delete file: %s" % fullpath)
            self.statusBar.showMessage(translate('statusbar',"Done."), 3000)
wower_captcha.py 文件源码 项目:pythoner 作者: jsRuner 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self,filepath):
        self.imgpath = filepath
        self.fonts =[] #???????????
        self.str = '' #??????????

        binaryimg = 'wower_binary.png'

        cutdir = './cutimgs/'

        #????binary???cutimgs???
        if os.path.exists(binaryimg):
            os.remove(binaryimg)
        if os.path.exists(cutdir) and  os.path.isdir(cutdir):
            for f in os.listdir(cutdir):
                os.remove(cutdir+f)
            # os.removedirs(cutdir)
        #?????
        else:
            os.mkdir(cutdir)



    #???????????
captcha2.py 文件源码 项目:pythoner 作者: jsRuner 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self,filepath):
        self.imgpath = filepath
        self.fonts =[] #???????????
        self.str = '' #??????????

        binaryimg = 'binary.png'

        cutdir = './cutimgs/'

        #????binary???cutimgs???
        if os.path.exists(binaryimg):
            os.remove(binaryimg)
        if os.path.exists(cutdir) and  os.path.isdir(cutdir):
            for f in os.listdir(cutdir):
                os.remove(cutdir+f)
            os.removedirs(cutdir)
        #??????
        os.mkdir(cutdir)


    #???????????
hefei_captcha.py 文件源码 项目:pythoner 作者: jsRuner 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(self,filepath):
        self.imgpath = filepath
        self.fonts =[] #???????????
        self.str = '' #??????????

        binaryimg = 'hefeicc_binary.png'

        cutdir = './cutimgs/'

        #????binary???cutimgs???
        if os.path.exists(binaryimg):
            os.remove(binaryimg)
        if os.path.exists(cutdir) and  os.path.isdir(cutdir):
            for f in os.listdir(cutdir):
                os.remove(cutdir+f)
            # os.removedirs(cutdir)
        #?????
        else:
            os.mkdir(cutdir)



    #???????????
captcha.py 文件源码 项目:pythoner 作者: jsRuner 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self,filepath):
        self.imgpath = filepath
        self.fonts =[] #???????????
        self.str = '' #??????????

        binaryimg = 'binary.png'

        cutdir = './cutimgs/'

        #????binary???cutimgs???
        if os.path.exists(binaryimg):
            os.remove(binaryimg)
        if os.path.exists(cutdir) and  os.path.isdir(cutdir):
            for f in os.listdir(cutdir):
                os.remove(cutdir+f)
            os.removedirs(cutdir)
        #??????
        os.mkdir(cutdir)


    #???????????
test_file_manager.py 文件源码 项目:kalliope 作者: kalliope-project 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_create_directory(self):
        """
        Test to create a new directory.
        """
        # set up
        cache_path = "/tmp/kalliope/tests/testDirectory"
        if os.path.exists(cache_path):
            os.removedirs(cache_path)

        # Test FileManager.create_directory
        FileManager.create_directory(cache_path)
        self.assertTrue(os.path.exists(cache_path),
                        "Fail creating a directory to the path ")

        # Remove the directory
        os.removedirs(cache_path)
serve.py 文件源码 项目:earmark 作者: lowerquality 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def _process_upload(self, upl, session_id):
        path = os.path.join(self.db.dbdir, '_attachments', upl['path'])

        print 'processing', path

        # XXX: use a tempdir
        outdir = os.path.join(self.db.dbdir, upl['filename'])
        sess = SocketTranscriptionSession(outdir, self.factory, session_id, self.factory.gen_hclg_filename)

        BUF_LEN = 200
        for chunk in numm3.sound_chunks(path, nchannels=1, R=8000, chunksize=BUF_LEN):
            sess.feed(chunk)

        sess.stop()
        sess.join()

        # Clean up: remove the tempdir and the original upload
        os.removedirs(outdir)
        os.remove(path)
1.py 文件源码 项目:python_mini_projeler 作者: o11 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def klasor_silme():
    dizin = {}
    print "\nno\t\tdosya ad?\n--\t\t---------"

    for a, i in enumerate(os.listdir(os.curdir)):
        print "{}\t\t{}".format(a, i)
        dizin[a] = i

    try:
        d_no = input("Silmek istedi?iniz dosya numaras?: ")
        path = dizin[d_no]
        os.removedirs(path)

    except KeyError:
        print "Klasör silinemedi !"
    except NameError:
        print "Klasör silinemedi !"
    except SyntaxError:
        print "Klasör silinemedi !"
remove_stale_pyc_files.py 文件源码 项目:buildroot 作者: flutter 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def RemoveAllStalePycFiles(base_dir):
  """Scan directories for old .pyc files without a .py file and delete them."""
  for dirname, _, filenames in os.walk(base_dir):
    if '.svn' in dirname or '.git' in dirname:
      continue
    for filename in filenames:
      root, ext = os.path.splitext(filename)
      if ext != '.pyc':
        continue

      pyc_path = os.path.join(dirname, filename)
      py_path = os.path.join(dirname, root + '.py')

      try:
        if not os.path.exists(py_path):
          os.remove(pyc_path)
      except OSError:
        # Wrap OS calls in try/except in case another process touched this file.
        pass

    try:
      os.removedirs(dirname)
    except OSError:
      # Wrap OS calls in try/except in case another process touched this dir.
      pass
oscilloscope.py 文件源码 项目:spyking-circus-ort 作者: spyking-circus 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def _initialize(self):

        self.data_available = False
        self.batch = None
        self.thresholds = None
        self.peaks = None
        self.data_lines = None
        self.threshold_lines = None
        self.peak_points = None
        self.output_directory = self.path
        if self.output_directory is not None:
            if os.path.exists(self.output_directory):
                # TODO check that the directory contains only .svg files.
                # os.removedirs(self.output_directory)
                pass
            os.makedirs(self.output_directory)

        return
__init__.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
plot.py 文件源码 项目:spyking-circus 作者: spyking-circus 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def view_trigger_snippets(trigger_snippets, chans, save=None):
    # Create output directory if necessary.
    if os.path.exists(save):
        for f in os.listdir(save):
            p = os.path.join(save, f)
            os.remove(p)
        os.removedirs(save)
    os.makedirs(save)
    # Plot figures.
    fig = pylab.figure()
    for (c, chan) in enumerate(chans):
        ax = fig.add_subplot(1, 1, 1)
        for n in xrange(0, trigger_snippets.shape[2]):
            y = trigger_snippets[:, c, n]
            x = numpy.arange(- (y.size - 1) / 2, (y.size - 1) / 2 + 1)
            b = 0.5 + 0.5 * numpy.random.rand()
            ax.plot(x, y, color=(0.0, 0.0, b), linestyle='solid')
        y = numpy.mean(trigger_snippets[:, c, :], axis=1)
        x = numpy.arange(- (y.size - 1) / 2, (y.size - 1) / 2 + 1)
        ax.plot(x, y, color=(1.0, 0.0, 0.0), linestyle='solid')
        ax.grid(True)
        ax.set_xlim([numpy.amin(x), numpy.amax(x)])
        ax.set_title("Channel %d" %chan)
        ax.set_xlabel("time")
        ax.set_ylabel("amplitude")
        if save is not None:
            # Save plot.
            filename = "channel-%d.png" %chan
            path = os.path.join(save, filename)
            pylab.savefig(path)
        fig.clf()
    if save is None:
        pylab.show()
    else:
        pylab.close(fig)
    return
__init__.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
util.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
misc.py 文件源码 项目:pip-update-requirements 作者: alanhamlett 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
test_downloader.py 文件源码 项目:chakin 作者: chakki-works 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_download_nest_dir(self):
        dir_name = 'data/ja'
        path = download(number=self.number, save_dir=dir_name)
        self.assertTrue(os.path.exists(path))
        os.remove(path)
        os.removedirs(dir_name)
__init__.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
_url.py 文件源码 项目:pytablereader 作者: thombashi 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __del__(self):
        if typepy.is_null_string(self.__temp_dir_path):
            return

        os.removedirs(self.__temp_dir_path)
        self.__temp_dir_path = None
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
__init__.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
__init__.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass
__init__.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def renames(old, new):
    """Like os.renames(), but handles renaming across devices."""
    # Implementation borrowed from os.renames().
    head, tail = os.path.split(new)
    if head and tail and not os.path.exists(head):
        os.makedirs(head)

    shutil.move(old, new)

    head, tail = os.path.split(old)
    if head and tail:
        try:
            os.removedirs(head)
        except OSError:
            pass


问题


面经


文章

微信
公众号

扫码关注公众号