当前位置: 首页>>代码示例>>Python>>正文


Python mozfile.rmtree函数代码示例

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


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


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