• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mozfile.rmtree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mozfile.rmtree函数的典型用法代码示例。如果您正苦于以下问题:Python rmtree函数的具体用法?Python rmtree怎么用?Python rmtree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rmtree函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __del__

 def __del__(self):
     try:
         Launcher.__del__(self)
     finally:
         # always remove tempdir
         if self.tempdir is not None:
             rmtree(self.tempdir)
开发者ID:Gioyik,项目名称:mozregression,代码行数:7,代码来源:launchers.py


示例2: cleanup

 def cleanup(self):
     try:
         Launcher.cleanup(self)
     finally:
         # always remove tempdir
         if self.tempdir is not None:
             rmtree(self.tempdir)
开发者ID:JohanLorenzo,项目名称:mozregression,代码行数:7,代码来源:launchers.py


示例3: test_noclean

    def test_noclean(self):
        """test `restore=True/False` functionality"""

        profile = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        try:

            # empty initially
            self.assertFalse(bool(os.listdir(profile)))

            # make an addon
            stub = addon_stubs.generate_addon(name='empty-0-1.xpi',
                                              path=tmpdir)

            # install it with a restore=True AddonManager
            addons  = mozprofile.addons.AddonManager(profile, restore=True)
            addons.install_from_path(stub)

            # now its there
            self.assertEqual(os.listdir(profile), ['extensions'])
            extensions = os.path.join(profile, 'extensions', 'staged')
            self.assertTrue(os.path.exists(extensions))
            contents = os.listdir(extensions)
            self.assertEqual(len(contents), 1)

            # del addons; now its gone though the directory tree exists
            del addons
            self.assertEqual(os.listdir(profile), ['extensions'])
            self.assertTrue(os.path.exists(extensions))
            contents = os.listdir(extensions)
            self.assertEqual(len(contents), 0)

        finally:
            mozfile.rmtree(tmpdir)
            mozfile.rmtree(profile)
开发者ID:AutomatedTester,项目名称:mozbase,代码行数:35,代码来源:test_addons.py


示例4: test_basic

    def test_basic(self):
        """ Test mozhttpd can serve files """

        tempdir = tempfile.mkdtemp()

        # sizes is a dict of the form: name -> [size, binary_string, filepath]
        sizes = {'small': [128], 'large': [16384]}

        for k in sizes.keys():
            # Generate random binary string
            sizes[k].append(os.urandom(sizes[k][0]))

            # Add path of file with binary string to list
            fpath = os.path.join(tempdir, k)
            sizes[k].append(fpath)

            # Write binary string to file
            with open(fpath, 'wb') as f:
                f.write(sizes[k][1])

        server = mozhttpd.MozHttpd(docroot=tempdir)
        server.start()
        server_url = server.get_url()

        # Retrieve file and check contents matchup
        for k in sizes.keys():
            retrieved_content = mozfile.load(server_url + k).read()
            self.assertEqual(retrieved_content, sizes[k][1])

        # Cleanup tempdir and related files
        mozfile.rmtree(tempdir)
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:31,代码来源:basic.py


示例5: test_get_binary_error

    def test_get_binary_error(self):
        """ Test an InvalidBinary error is raised """

        tempdir_empty = tempfile.mkdtemp()
        self.assertRaises(mozinstall.InvalidBinary, mozinstall.get_binary,
                          tempdir_empty, 'firefox')
        mozfile.rmtree(tempdir_empty)
开发者ID:AutomatedTester,项目名称:mozbase,代码行数:7,代码来源:test.py


示例6: test_remove_directory

 def test_remove_directory(self):
     self.assertTrue(os.path.isdir(self.tempdir))
     try:
         mozfile.rmtree(self.tempdir)
     except:
         shutil.rmtree(self.tempdir)
         raise
     self.assertFalse(os.path.exists(self.tempdir))
开发者ID:jpetrell,项目名称:gecko-dev,代码行数:8,代码来源:test_rmtree.py


示例7: tearDown

    def tearDown(self):
        mozfile.rmtree(self.tmpdir)

        self.am = None
        self.profile = None

        # Bug 934484
        # Sometimes the profile folder gets recreated at the end and will be left
        # behind. So we should ensure that we clean it up correctly.
        mozfile.rmtree(self.profile_path)
开发者ID:jugglinmike,项目名称:mozbase,代码行数:10,代码来源:test_addons.py


示例8: _install

 def _install(self, dest):
     self.tempdir = tempfile.mkdtemp()
     try:
         self.binary = mozinstall.get_binary(
             mozinstall.install(src=dest, dest=self.tempdir),
             self.app_name
         )
     except:
         rmtree(self.tempdir)
         raise
开发者ID:JohanLorenzo,项目名称:mozregression,代码行数:10,代码来源:launchers.py


示例9: remove_addon

    def remove_addon(self, addon_id):
        """Remove the add-on as specified by the id

        :param addon_id: id of the add-on to be removed
        """
        path = self.get_addon_path(addon_id)
        if os.path.isdir(path):
            mozfile.rmtree(path)
        elif os.path.isfile(path):
            os.remove(path)
开发者ID:k0s,项目名称:mozbase,代码行数:10,代码来源:addons.py


示例10: test_remove_directory

 def test_remove_directory(self):
     tempdir = create_stub()
     self.assertTrue(os.path.exists(tempdir))
     self.assertTrue(os.path.isdir(tempdir))
     try:
         mozfile.rmtree(tempdir)
     except:
         shutil.rmtree(tempdir)
         raise
     self.assertFalse(os.path.exists(tempdir))
开发者ID:Callek,项目名称:mozbase,代码行数:10,代码来源:test.py


示例11: test_remove_directory_after_closing_file

    def test_remove_directory_after_closing_file(self):
        """ Test that the call to mozfile.rmtree succeeds on
            all platforms after file is closed """

        filepath = os.path.join(self.tempdir, *stubs.files[1])
        with open(filepath, "w") as f:
            f.write("foo-bar")
        # Delete directory tree
        mozfile.rmtree(self.tempdir)
        # Check deletion is successful
        self.assertFalse(os.path.exists(self.tempdir))
开发者ID:jpetrell,项目名称:gecko-dev,代码行数:11,代码来源:test_rmtree.py


示例12: test_remove_directory_with_open_file

 def test_remove_directory_with_open_file(self):
     """ Tests handling when removing a directory tree
         which has a file in it is still open """
     # Open a file in the generated stub
     filepath = os.path.join(self.tempdir, *stubs.files[1])
     f = file(filepath, "w")
     f.write("foo-bar")
     # keep file open and then try removing the dir-tree
     if mozinfo.isWin:
         # On the Windows family WindowsError should be raised.
         self.assertRaises(WindowsError, mozfile.rmtree, self.tempdir)
     else:
         # Folder should be deleted on all other platforms
         mozfile.rmtree(self.tempdir)
         self.assertFalse(os.path.exists(self.tempdir))
开发者ID:jpetrell,项目名称:gecko-dev,代码行数:15,代码来源:test_rmtree.py


示例13: test_install_from_manifest

    def test_install_from_manifest(self):

        temp_manifest = addon_stubs.generate_manifest()
        m = ManifestParser()
        m.read(temp_manifest)
        addons = m.get()
        # Obtain details of addons to install from the manifest
        addons_to_install = [self.am.addon_details(x['path'])['id'] for x in addons]

        self.am.install_from_manifest(temp_manifest)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_installed.sort(), addons_to_install.sort())
        # Cleanup the temporary addon and manifest directories
        mozfile.rmtree(os.path.dirname(temp_manifest))
开发者ID:markrcote,项目名称:mozbase,代码行数:16,代码来源:test_addons.py


示例14: test_install_from_path

    def test_install_from_path(self):

        addons_to_install = []
        addons_installed = []

        # Generate installer stubs and install them
        tmpdir = tempfile.mkdtemp()
        for t in ['empty-0-1.xpi', 'another-empty-0-1.xpi']:
            temp_addon = addon_stubs.generate_addon(name=t, path=tmpdir)
            addons_to_install.append(self.am.addon_details(temp_addon)['id'])
            self.am.install_from_path(temp_addon)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_to_install.sort(), addons_installed.sort())
        # Cleanup the temporary addon directories
        mozfile.rmtree(tmpdir)
开发者ID:markrcote,项目名称:mozbase,代码行数:17,代码来源:test_addons.py


示例15: test_noclean

    def test_noclean(self):
        """test `restore=True/False` functionality"""

        server = mozhttpd.MozHttpd(docroot=os.path.join(here, 'addons'))
        server.start()

        profile = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()

        try:
            # empty initially
            self.assertFalse(bool(os.listdir(profile)))

            # make an addon
            addons = []
            addons.append(generate_addon('[email protected]',
                                         path=tmpdir))
            addons.append(server.get_url() + 'empty.xpi')

            # install it with a restore=True AddonManager
            am = mozprofile.addons.AddonManager(profile, restore=True)

            for addon in addons:
                am.install_from_path(addon)

            # now its there
            self.assertEqual(os.listdir(profile), ['extensions'])
            staging_folder = os.path.join(profile, 'extensions', 'staged')
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(len(os.listdir(staging_folder)), 2)

            # del addons; now its gone though the directory tree exists
            downloaded_addons = am.downloaded_addons
            del am

            self.assertEqual(os.listdir(profile), ['extensions'])
            self.assertTrue(os.path.exists(staging_folder))
            self.assertEqual(os.listdir(staging_folder), [])

            for addon in downloaded_addons:
                self.assertFalse(os.path.isfile(addon))

        finally:
            mozfile.rmtree(tmpdir)
            mozfile.rmtree(profile)
开发者ID:jugglinmike,项目名称:mozbase,代码行数:45,代码来源:test_addons.py


示例16: generate_addon

def generate_addon(addon_id, path=None, name=None, xpi=True):
    """
    Method to generate a single addon.

    :param addon_id: id of an addon to generate from the stubs dictionary
    :param path: path where addon and .xpi should be generated
    :param name: name for the addon folder or .xpi file
    :param xpi: Flag if an XPI or folder should be generated

    Returns the file-path of the addon's .xpi file
    """

    if addon_id not in stubs.keys():
        raise IOError('Requested addon stub "%s" does not exist' % addon_id)

    # Generate directory structure for addon
    try:
        tmpdir = path or tempfile.mkdtemp()
        addon_dir = os.path.join(tmpdir, name or addon_id)
        os.mkdir(addon_dir)
    except IOError:
        raise IOError('Could not generate directory structure for addon stub.')

    # Write install.rdf for addon
    if stubs[addon_id]:
        install_rdf = os.path.join(addon_dir, 'install.rdf')
        with open(install_rdf, 'w') as f:
            manifest = os.path.join(here, 'install_manifests', stubs[addon_id])
            f.write(open(manifest, 'r').read())

    if not xpi:
        return addon_dir

    # Generate the .xpi for the addon
    xpi_file = os.path.join(tmpdir, (name or addon_id) + '.xpi')
    with zipfile.ZipFile(xpi_file, 'w') as x:
        x.write(install_rdf, install_rdf[len(addon_dir):])

    # Ensure we remove the temporary folder to not install the addon twice
    mozfile.rmtree(addon_dir)

    return xpi_file
开发者ID:luke-chang,项目名称:gecko-1,代码行数:42,代码来源:addon_stubs.py


示例17: __init__

  def __init__(self, **kwargs):
    debug("uninstall constructor")
    assert (kwargs['dest'] != "" and kwargs['dest'] != None)
    assert (kwargs['productName'] != "" and kwargs['productName'] != None)
    assert (kwargs['branch'] != "" and kwargs['dest'] != None)
    self.dest = kwargs['dest']
    self.productName = kwargs['productName']
    self.branch = kwargs['branch']

    # Handle the case where we haven't installed yet
    if not os.path.exists(self.dest):
      return

    if getPlatform() == "Windows":
      try:
        self.doWindowsUninstall()
      except:
        debug("Windows Uninstall threw - not overly urgent or worrisome")
    if os.path.exists(self.dest):
      try:
        os.rmdir(self.dest)
      except OSError:
        # Directories are still there - kill them all!
        rmtree(self.dest)
开发者ID:jwir3,项目名称:proton-pack,代码行数:24,代码来源:mozInstall.py


示例18: test_profileprint

    def test_profileprint(self):
        """
        test the summary function
        """

        keys = set(['Files', 'Path', 'user.js'])
        ff_prefs = mozprofile.FirefoxProfile.preferences  # shorthand
        pref_string = '\n'.join(['%s: %s' % (key, ff_prefs[key])
                                 for key in sorted(ff_prefs.keys())])

        tempdir = tempfile.mkdtemp()
        try:
            profile = mozprofile.FirefoxProfile(tempdir)
            parts = profile.summary(return_parts=True)
            parts = dict(parts)

            self.assertEqual(parts['Path'], tempdir)
            self.assertEqual(set(parts.keys()), keys)
            self.assertEqual(pref_string, parts['user.js'].strip())

        except:
            raise
        finally:
            mozfile.rmtree(tempdir)
开发者ID:Wafflespeanut,项目名称:gecko-dev,代码行数:24,代码来源:test_profile_view.py


示例19: tearDown

 def tearDown(self):
     mozfile.rmtree(self.tmpdir)
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:2,代码来源:test_files.py


示例20: remove_tempdir

 def remove_tempdir(self):
     if self.tempdir:
         rmtree(self.tempdir)
         self.tempdir = None
开发者ID:AaronMT,项目名称:mozregression,代码行数:4,代码来源:runnightly.py



注:本文中的mozfile.rmtree函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mozfile.NamedTemporaryFile类代码示例发布时间:2022-05-27
下一篇:
Python mozfile.remove函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap