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


Python Path.rmtree方法代码示例

本文整理汇总了Python中unipath.Path.rmtree方法的典型用法代码示例。如果您正苦于以下问题:Python Path.rmtree方法的具体用法?Python Path.rmtree怎么用?Python Path.rmtree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unipath.Path的用法示例。


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

示例1: set_up_and_import_file

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
    def set_up_and_import_file(self):
        temp_dir = Path(tempfile.mkdtemp())
        temp_file = Path(temp_dir, 'test.csv')
        with open(temp_file, 'a') as f:
            header = ''
            header_fields = [
                'route',
                'account_number',
                'house_number',
                'pre_direction',
                'street',
                'street_type',
                'post_direction',
                'unit',
                'city_state_zip'
            ]
            
            for x, field in enumerate(header_fields):
                if x + 1 == len(header_fields):
                    header = header + field + '\n'
                else:
                    header = header + field + ','

            f.write(header)
            f.write('123,123,123,S,TEST,RD,S,#5B,"TEST, FL 32174"')

        mommy.make(
            'route_update.Directional', direction='South', abbreviation='S'
        )
        mommy.make('route_update.StreetType', name='Road', abbreviation='RD')
        mommy.make('route_update.State', name='Florida', abbreviation='FL')

        Location.create_active_locations_from_file(temp_file)

        temp_dir.rmtree()
开发者ID:cfc603,项目名称:publication_delivery,代码行数:37,代码来源:test_models.py

示例2: double_dump_test

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
def double_dump_test():
    """
    Perform a "double dump test" on every demo database.
    TODO: convert this to a Lino management command.
    """
    raise Exception("Not yet converted after 20150129")
    if len(env.demo_databases) == 0:
        return
    a = Path(env.temp_dir, 'a')
    b = Path(env.temp_dir, 'b')
    rmtree_after_confirm(a)
    rmtree_after_confirm(b)
    #~ if not confirm("This will possibly break the demo databases. Are you sure?"):
        #~ return
    #~ a.mkdir()
    with lcd(env.temp_dir):
        for db in env.demo_databases:
            if a.exists():
                a.rmtree()
            if b.exists():
                b.rmtree()
            local("django-admin.py dump2py --settings=%s --traceback a" % db)
            local(
                "django-admin.py run --settings=%s --traceback a/restore.py" %
                db)
            local("django-admin.py dump2py --settings=%s --traceback b" % db)
            local("diff a b")
开发者ID:khchine5,项目名称:atelier,代码行数:29,代码来源:fablib.py

示例3: Test_Inupypi

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
class Test_Inupypi(unittest.TestCase):
    def setUp(self):
        self.app = inupypi.app.test_client()
        self.workspace = Path(tempfile.mkdtemp())
        self.packages = ['p1', 'p2', 'p3', 'p4']
        self.files = ['f1', 'f2', 'f3', 'f4']
        self.app.application.config['INUPYPI_REPO'] = self.workspace

    def tearDown(self):
        self.workspace.rmtree()

    def test_app_with_missing_package_dir(self):
        self.app.application.config['INUPYPI_REPO'] = Path(self.workspace, 'a')
        assert self.app.get('/').status_code == 500
        assert '500:' in self.app.get('/').data

    def test_app_without_packages(self):
        assert 'inetutils PyPI Server' in self.app.get('/').data
        assert 'Available Packages' not in self.app.get('/').data

    def test_app_with_package_folders(self):
        env_create_packages(self.workspace, self.packages)
        env_create_package_files(self.workspace, self.packages, self.files)
        assert 'inetutils PyPI Server' in self.app.get('/').data
        assert 'Available EggBaskets' in self.app.get('/').data

    def test_app_package(self):
        env_create_packages(self.workspace, self.packages)

        for p in self.packages:
            for f in self.files:
                page = self.app.get('/'+p+'/').data
                assert '404 - Page not found' not in page
                assert f not in page

        env_create_package_files(self.workspace, self.packages, self.files)

        for p in self.packages:
            for f in self.files:
                assert f in self.app.get('/test/'+p+'/').data

    def test_app_package_file(self):
        env_create_packages(self.workspace, self.packages)

        for p in self.packages:
            for f in self.files:
                response = self.app.get('/test/'+p+'/get/'+f)
                assert response.status_code == 404

        env_create_package_files(self.workspace, self.packages, self.files)

        for p in self.packages:
            for f in self.files:
                f = '%s.tar.gz' % f
                response = self.app.get('/test/'+p+'/get/'+f)
                assert response.status_code == 200
                assert response.content_type == 'application/x-tar'
                assert response.headers.get('Content-Disposition') == \
                        'attachment; filename=%s' % f
开发者ID:Zhaf,项目名称:inupypi,代码行数:61,代码来源:test_inupypi.py

示例4: delete

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
 def delete(self, name):
     user = User(self.path, self.git, name)
     dest = Path(self.path, 'keydir/%s' % name)
     if not dest.exists():
         raise ValueError('Repository %s not existing.' % name)
     dest.rmtree()
     self.git.commit([str(dest)], 'Deleted user %s.' % name)
     
     return user
开发者ID:Codevolve,项目名称:pyolite,代码行数:11,代码来源:user.py

示例5: test_load_states_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
    def test_load_states_space_end_of_line(self):
        temp_dir = Path(tempfile.mkdtemp())
        temp_file = Path(temp_dir, 'test.txt')
        temp_file.write_file('Florida FL \n')

        State.load_states(temp_file.absolute())

        temp_dir.rmtree()

        self.assertEqual('Florida', State.objects.first().name)
        self.assertEqual('FL', State.objects.first().abbreviation)
开发者ID:cfc603,项目名称:publication_delivery,代码行数:13,代码来源:test_models.py

示例6: test_load_directionals_no_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
    def test_load_directionals_no_space_end_of_line(self):
        temp_dir = Path(tempfile.mkdtemp())
        temp_file = Path(temp_dir, 'test.txt')
        temp_file.write_file('Northeast NE\n')

        Directional.load_directionals(temp_file.absolute())

        temp_dir.rmtree()

        self.assertEqual('Northeast', Directional.objects.first().direction)
        self.assertEqual('NE', Directional.objects.first().abbreviation)
开发者ID:cfc603,项目名称:publication_delivery,代码行数:13,代码来源:test_models.py

示例7: test_load_street_types_no_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
    def test_load_street_types_no_space_end_of_line(self):
        temp_dir = Path(tempfile.mkdtemp())
        temp_file = Path(temp_dir, 'test.txt')
        temp_file.write_file('VILLAGE VILL VLG\n')

        StreetType.load_street_types(temp_file.absolute())

        temp_dir.rmtree()

        self.assertEqual('VILLAGE VILL', StreetType.objects.first().name)
        self.assertEqual('VLG', StreetType.objects.first().abbreviation)
开发者ID:cfc603,项目名称:publication_delivery,代码行数:13,代码来源:test_models.py

示例8: main

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
def main():
    if len(sys.argv) != 2 or sys.argv[1] not in ['KNMP', 'Stanford', 'both']:
        print("Usage: python %s <dataset>" % sys.argv[0])
        print("\tDataset should be either 'KNMP' or 'Stanford' or 'both'")
        sys.exit(1)

    # create a clean temporary directory
    if os.path.exists("tmp"):
        shutil.rmtree("tmp")
    os.makedirs("tmp")
    work_dir = Path("tmp")
    work_dir.rmtree()
    work_dir.mkdir()

    if sys.argv[1] in ['KNMP', 'both']:
        create('KNMP', work_dir)
    if sys.argv[1] in ['Stanford', 'both']:
        create('Stanford', work_dir)
开发者ID:XeryusTC,项目名称:handwritingrecog,代码行数:20,代码来源:create_segments.py

示例9: env_create_package_files

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
def env_create_package_files(workspace, packages, files):
    for p in packages:
        if files:
            for f in files:
                f = Path(workspace, 'test', p, f)
                f.mkdir(parents=True)
                version = '.'.join([x for x in f.name if x.isdigit()])
                i = env_create_package_pkginfo(p, version)
                Path(f, '%s.egg-info' % f.name).mkdir()
                Path(f, 'PKG-INFO').write_file(i)
                Path(f, '%s.egg-info' % f.name, 'PKG-INFO').write_file(i)

                os.chdir(f.parent)
                tar = tarfile.open('%s.tar.gz' % f, 'w:gz')
                tar.add('%s' % f.name)
                tar.close()
                f.rmtree()
        else:
            Path(workspace, 'test', p).mkdir(parents=True)
开发者ID:Zhaf,项目名称:inupypi,代码行数:21,代码来源:packages.py

示例10: setup_test_sdist

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
def setup_test_sdist():
    if len(env.demo_databases) == 0:
        return
    ve_path = Path(env.temp_dir, 'test_sdist')
    #~ if ve_path.exists():
    ve_path.rmtree()
    #~ rmtree_after_confirm(ve_path)
    ve_path.mkdir()
    script = ve_path.child('tmp.sh')

    context = dict(name=env.SETUP_INFO['name'], sdist_dir=env.sdist_dir,
                   ve_path=ve_path)
    #~ file(script,'w').write(TEST_SDIST_TEMPLATE % context)
    txt = TEST_SDIST_TEMPLATE % context
    for db in env.demo_databases:
        txt += "django-admin.py test --settings=%s --traceback\n" % db
    script.write_file(txt)
    script.chmod(0o777)
    with lcd(ve_path):
        local(script)
开发者ID:ManuelWeidmann,项目名称:atelier,代码行数:22,代码来源:fablib.py

示例11: test_rmtree_broken_symlink

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
 def test_rmtree_broken_symlink(self):
     symlink = Path(self.d, "symlink")
     symlink.write_link("broken")
     assert symlink.lexists()
     symlink.rmtree()
     assert not symlink.lexists()
开发者ID:Mondego,项目名称:pyreco,代码行数:8,代码来源:allPythonContent.py

示例12: temp_dir

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
def temp_dir():
    tmp = Path(tempfile.mkdtemp())
    try:
        yield tmp
    finally:
        tmp.rmtree()
开发者ID:geoslegend,项目名称:pywps-4,代码行数:8,代码来源:wpsserver.py

示例13: DictToLocationTest

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
class DictToLocationTest(TestCase):

    temp_dir = None
    temp_file = None

    def setUp(self):
        self.temp_dir = Path(tempfile.mkdtemp())
        self.temp_file = Path(self.temp_dir, 'test.csv')
        with open(self.temp_file, 'a') as f:
            header = ''
            header_fields = [
                'route',
                'account_number',
                'house_number',
                'pre_direction',
                'street',
                'street_type',
                'post_direction',
                'unit',
                'city_state_zip'
            ]
            
            for x, field in enumerate(header_fields):
                if x + 1 == len(header_fields):
                    header = header + field + '\n'
                else:
                    header = header + field + ','

            f.write(header)

        mommy.make(
            'route_update.Directional', direction='South', abbreviation='S'
        )
        mommy.make('route_update.StreetType', name='Road', abbreviation='RD')
        mommy.make('route_update.State', name='Florida', abbreviation='FL')

        super(DictToLocationTest, self).setUp()

    def tearDown(self):
        self.temp_dir.rmtree()
        super(DictToLocationTest, self).tearDown()

    def add_record_to_file(self):
        with open(self.temp_file, 'a') as f:
            f.write('123,123,123,S,TEST,RD,S,#5B,"TEST, FL 32174"')

    def get_dict_to_location(self):
        with open(self.temp_file, 'r') as f:
            csv_reader = csv.DictReader(f, delimiter=',', quotechar='"')
            for row in csv_reader:
                loc = DictToLocation(row)
        return loc

    def test_set_route(self):
        self.add_record_to_file()
        loc = self.get_dict_to_location()

        self.assertIsInstance(loc.route, Route)
        self.assertEqual('123', str(Route.objects.first().number))

    def test_set_house_number(self):
        self.add_record_to_file()
        loc = self.get_dict_to_location()

        self.assertIsInstance(loc.house_number, HouseNumber)
        self.assertEqual('123', HouseNumber.objects.first().number)

    def test_set_pre_direction_not_none(self):
        self.add_record_to_file()
        loc = self.get_dict_to_location()

        self.assertIsInstance(loc.pre_direction, Directional)
        self.assertEqual('S', Directional.objects.first().abbreviation)
        self.assertEqual(1, Directional.objects.all().count())

    def test_set_pre_direction_none(self):
        with open(self.temp_file, 'a') as f:
            f.write('123,123,123,,TEST,RD,S,#5B,"TEST, FL 32174"')
        loc = self.get_dict_to_location()

        self.assertNotIsInstance(loc.pre_direction, Directional)
        self.assertIsNone(loc.pre_direction)

    def test_set_street(self):
        self.add_record_to_file()
        loc = self.get_dict_to_location()

        self.assertIsInstance(loc.street, Street)
        self.assertEqual('TEST', Street.objects.first().name)

    def test_set_street_type_not_none(self):
        self.add_record_to_file()
        loc = self.get_dict_to_location()

        self.assertIsInstance(loc.street_type, StreetType)
        self.assertEqual('RD', StreetType.objects.first().abbreviation)
        self.assertEqual(1, StreetType.objects.all().count())

    def test_set_street_type_none(self):
        with open(self.temp_file, 'a') as f:
#.........这里部分代码省略.........
开发者ID:cfc603,项目名称:publication_delivery,代码行数:103,代码来源:test_others.py

示例14: Test_Packages

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
class Test_Packages(unittest.TestCase):
    def setUp(self):
        self.app = app.test_client()
        self.workspace = Path(tempfile.mkdtemp())
        self.packages = ['p1', 'p2', 'p3', 'p4']
        self.files = ['f1', 'f2', 'f3', 'f4']
        self.files.sort(reverse=True)

        self.app.application.config['INUPYPI_REPO'] = self.workspace

    def tearDown(self):
        self.workspace.rmtree()

    def test_get_packages_without_packages_folder(self):
        self.app.application.config['INUPYPI_REPO'] = Path(self.workspace, 'a')

        try:
            get_packages('test')
            return False
        except:
            return True

    def test_get_packages(self):
        self.app.application.config['INUPYPI_REPO'] = self.workspace
        env_create_packages(self.workspace, self.packages)
        env_create_package_files(self.workspace, self.packages, self.files)
        created_packages = [Path(self.workspace, 'test', package)
                for package in self.packages]
        packages = [p.filepath for p in get_packages('test')]
        assert created_packages == packages

    def test_get_packages_from_folders_only(self):
        self.app.application.config['INUPYPI_REPO'] = self.workspace
        env_create_packages(self.workspace, self.packages)
        env_create_package_files(self.workspace, self.packages, self.files)

        packages_and_files = sorted([Path(package)
                for package in self.packages + self.files])

        created_packages = [Path(self.workspace, 'test', package)
                for package in self.packages]
        packages = [p.filepath for p in get_packages('test')]

        assert get_packages('test') != packages_and_files
        assert created_packages == packages

    def test_get_package_files(self):
        self.app.application.config['INUPYPI_REPO'] = self.workspace
        env_create_packages(self.workspace, self.packages)

        for p in self.packages:
            assert get_package_files('test', p) == []

        env_create_package_files(self.workspace, self.packages, self.files)

        for p in self.packages:
            files = sorted([Path(self.workspace, 'test', p, '%s.tar.gz' % f)
                    for f in self.files])
            package_files = sorted([pkg.filepath
                for pkg in get_package_files('test', p)])
            assert package_files == files

    def test_get_current_package(self):
        self.app.application.config['INUPYPI_REPO'] = self.workspace
        env_create_packages(self.workspace, self.packages)
        env_create_package_files(self.workspace, self.packages, self.files)

        for p in self.packages:
            created_packages = Path(self.workspace, 'test', p, '%s.tar.gz' %
                    sorted(self.files, reverse=True)[0])
            assert get_current_package('test', p) == created_packages

    def test_get_file(self):
        self.app.application.config['INUPYPI_REPO'] = self.workspace
        env_create_packages(self.workspace, self.packages)
        env_create_package_files(self.workspace, self.packages, self.files)
        for p in self.packages:
            for f in self.files:
                assert get_file('test', p, f) == False

        for p in self.packages:
            for f in self.files:
                f = '%s.tar.gz' % f
                assert get_file('test', p, f) == Path(self.workspace, 'test', p, f)
开发者ID:Zhaf,项目名称:inupypi,代码行数:86,代码来源:test_packages.py

示例15: ProjectInstaller

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import rmtree [as 别名]
class ProjectInstaller(Installer):

    flavor = 'django_custom'
    git_repo = 'https://github.com/Libermentix/project_skeletton_directory.git'

    def __init__(self, project_dir, project_name,
                 db_sudo=False, db_sudo_user=None, *args, **kwargs):

        super(ProjectInstaller, self).__init__(
            project_dir, project_name, *args, **kwargs
        )

        self.var_dict = dict(
            project_dir=add_trailing_slash(project_dir),
            project_name=add_trailing_slash(project_name)
        )

        self._tmp_dir = None

        if self.install_path.exists():
            self.install_path.rmtree()

        self.db_installer = DatabaseInstaller(
            project_dir=project_dir, project_name=project_name,
            sudo=db_sudo, sudo_user=db_sudo_user
        )
        self.django_installer = DjangoInstaller(
            project_dir=project_dir, project_name=project_name
        )

    def run(self):
        self.run_prepare_configuration()
        self.run_create_configuration()
        self.run_post_create_configuration()

    def run_prepare_configuration(self):
        self.get_git_repo()
        self.install_skeletton()
        self.install_requirements()


    def run_post_create_configuration(self):
        """
        run the the post_run_command_stack
        """
        self.db_installer()
        self.django_installer()

        self.move_to_venv(which_one='postactivate')
        self.move_to_venv(which_one='activate')

        self.finish_queued_commands()

        #run the post create configuration command for the children
        for item in self.db_installer.post_run_command_stack:
            # should be a callable or None
            if item: item()

        for item in self.django_installer.post_run_command_stack:
            # should be a callable or None
            if item:
                logger.info('%s: Executing a django_installer_script ...' % item)
                item()


    @property
    def requirements_file(self):
        return Path(
            self.install_path, 'requirements', 'base.txt'
        ).absolute()

    @property
    def repo_dir(self):
        #get last
        directory = self.git_repo.split('/')[-1:][0]
        #remove .git
        directory = directory.split('.')[0]
        return Path(self._tmp_dir, directory)

    def create_tmp_dir(self):
        # TODO:
        # Account for existing project paths, here it should ask to remove
        # or abort.
        self._tmp_dir = Path(self.install_path, 'tmp')
        self._tmp_dir.mkdir()
        self._tmp_dir.chdir()

    def delete_tmp_dir(self):
        self.project_dir.chdir()
        self._tmp_dir.rmtree()

    def get_git_repo(self):
        self.create_tmp_dir()
        logger.info('Cloning repository ...')

        if self.repo_dir.exists():
            logger.info('Repo dir exists removing it...')
            self.repo_dir.rmtree()

        git.Git().clone(self.git_repo)
#.........这里部分代码省略.........
开发者ID:Libermentix,项目名称:project_installer,代码行数:103,代码来源:project_installer.py


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