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


Python Path.chdir方法代码示例

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


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

示例1: load_inv_namespace

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
def load_inv_namespace(root_dir):
    """
    Execute the :xfile:`tasks.py` file of this project and return its
    `ns`.
    """
    # self._tasks_loaded = True
    
    tasks_file = root_dir.child('tasks.py')
    if not tasks_file.exists():
        return None
        # raise Exception("No tasks.py file in {}".format(root_dir))
        # return

    # print("20180428 load tasks.py from {}".format(root_dir))
    # http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
    # http://stackoverflow.com/questions/19009932/import-arbitrary-python-source-file-python-3-3
    # fqname = 'atelier.prj_%s' % self.index
    cwd = Path().resolve()
    root_dir.chdir()
    m = dict()
    m["__file__"] = str(tasks_file)
    with open(tasks_file) as f:
        exec(f.read(), m)
    cwd.chdir()
    return m['ns']
开发者ID:lino-framework,项目名称:atelier,代码行数:27,代码来源:projects.py

示例2: test_pdf_to_png

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
 def test_pdf_to_png(self):
     testdir = Path(r"C:\tmp\pdfprocessing\test")
     testdir.chdir()
     input_file = "testpdf.pdf"
     output_file = Path(r"C:\tmp\pdfprocessing\test\test_gs_pdf_to_png.png")
     gs = GhostScript()
     gs.pdf_to_png(input_file,output_file)
     self.assertTrue(output_file.exists(),"File")
开发者ID:aggerdom,项目名称:pdf-processing-utils,代码行数:10,代码来源:test_utilityclasses.py

示例3: get_setup_info

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
def get_setup_info(root_dir):
    if not root_dir.child('setup.py').exists():
        raise RuntimeError(
            "You must call 'fab' from a project's root directory.")
    # sys.path.insert(0, root_dir)
    # setup_module = __import__('setup')
    # print 20140610, root_dir
    # del sys.path[0]
    # return getattr(setup_module, 'SETUP_INFO', None)
    g = dict()
    g['__name__'] = 'not_main'
    cwd = Path().resolve()
    root_dir.chdir()
    execfile(root_dir.child('setup.py'), g)
    cwd.chdir()
    return g.get('SETUP_INFO')
开发者ID:khchine5,项目名称:atelier,代码行数:18,代码来源:projects.py

示例4: get_setup_info

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
def get_setup_info(root_dir):
    """
    Return `SETUP_INFO` defined in the :xfile:`setup.py` file of the
    specified `root_dir`.
    """
    setup_file = root_dir.child('setup.py')
    if not setup_file.exists():
        # print("20180118 no setup.py file in {}".format(root_dir.absolute()))
        return {}
        # raise RuntimeError(
        #     "You must call 'inv' from a project's root directory.")
    # sys.path.insert(0, root_dir)
    # setup_module = __import__('setup')
    # print 20140610, root_dir
    # del sys.path[0]
    # return getattr(setup_module, 'SETUP_INFO', None)
    g = dict()
    g['__name__'] = 'not_main'
    # g['__file__'] = setup_file
    cwd = Path().resolve()
    root_dir.chdir()
    with open("setup.py") as f:
        code = compile(f.read(), "setup.py", 'exec')
        try:
            exec(code, g)
        except SystemExit:
            cwd.chdir()
            raise Exception(
                "Oops, {} called sys.exit().\n"
                "Atelier requires the setup() call to be in a "
                "\"if __name__ == '__main__':\" condition.".format(
                    setup_file))
    cwd.chdir()
    info = g.get('SETUP_INFO')
    if info is None:
        raise Exception(
            "Oops, {} doesn't define a name SETUP_INFO.".format(
                setup_file))
    return info
开发者ID:lino-framework,项目名称:atelier,代码行数:41,代码来源:projects.py

示例5: load_tasks

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
    def load_tasks(self):
        """Load the :xfile:`tasks.py` of this project."""
        if self._tasks_loaded:
            return

        self._tasks_loaded = True
        self.name = self.nickname

        if not self.root_dir.child('tasks.py').exists():
            return

        fqname = 'atelier.prj_%s' % self.index
        cwd = Path().resolve()
        self.root_dir.chdir()
        # print("20160121 pseudo-importing file %s %s/tasks.py " % (
        #     self, self.root_dir))
        (fp, pathname, desc) = imp.find_module('tasks', [self.root_dir])
        m = imp.load_module(fqname, fp, pathname, desc)
        cwd.chdir()

        assert hasattr(m, 'ns')
        main_package = m.ns.main_package
        self.ns = m.ns

        if main_package is None:
            return
        self.name = main_package
        # self.name = name
        # removed 20140116:
        # self.dist = pkg_resources.get_distribution(name)
        self.module = import_module(main_package)
        self.SETUP_INFO = get_setup_info(self.root_dir)
        self.srcref_url = getattr(self.module, 'srcref_url', None)
        self.doc_trees = getattr(self.module, 'doc_trees', self.doc_trees)
        self.intersphinx_urls = getattr(
            self.module, 'intersphinx_urls', {})
开发者ID:khchine5,项目名称:atelier,代码行数:38,代码来源:projects.py

示例6: Installer

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
class Installer(object):
    install_path = None
    postactivate = None
    postdeactivate = None

    project_name = None
    project_dir = None

    var_dict = {}

    post_run_command_stack = []


    def __init__(self, project_dir, project_name, envwrapper=False,
                 *args, **kwargs):
        self.project_dir = Path(project_dir).absolute()
        self.project_name = project_name
        self.is_envwrapper = envwrapper

        # make all attributes overridable so that external applications
        # can make use of the pattern and reset the variable names
        for k, v in six.iteritems(kwargs):
            setattr(self, k, v)

        self.install_path = Path(self.project_dir, project_name)
        self.install_path.mkdir()
        self.install_path.chdir()

        self._environment_cache = False
        self._template_dir_cache = False
        self._template_cache = False

    @property
    def venv_folder(self):
        """
        extracts the venv folder from the environment variables ($WORKON_HOME,
        to be precise and combines it with the project name.
        """
        path = os.environ.copy().get('WORKON_HOME')
        if path:
            return Path(path)
        else:
            return None


    @property
    def template_env(self):
        """
        provides the template environment
        """
        if not getattr(self, '_environment_cache', False):
            self._environment_cache = Environment(
                loader=FileSystemLoader(self.get_template_dir())
            )

        return self._environment_cache

    def run_command(self, command, blocking=False):
        command = Command(command)

        command()

        if blocking:
            logger.debug('Waiting for command to finish...')
            command.wait()

        return True

    def finish_queued_commands(self):
        finish_queued_commands()

    def get_installer_name(self):
        return self.__class__.__name__.lower()

    def get_template_dir(self):
        if not getattr(self, '_template_cache', False):
            self._template_dir_cache = Path(Path(__file__).parent, 'templates')
        return self._template_dir_cache

    def get_template(self, which_one):
        """
        provides a wrapper around jinja2 get_template. Caches the result.
        returns a cached template
        """
        if not getattr(self, '_template_cache', False):
            self._template_cache = dict()

        if not self._template_cache.get(which_one, False):
            template_file = '%s.%s.sh' % (self.get_installer_name(), which_one)
            self._template_cache[which_one] = \
                self.template_env.get_template(template_file)

        return self._template_cache[which_one]

    def run_prepare_configuration(self):
        raise NotImplementedError('Must be implemented in subclass')

    def render_config_for_file_template(self, which_one):
        logger.info('preparing config variables for %s ...' % which_one)

#.........这里部分代码省略.........
开发者ID:Libermentix,项目名称:project_installer,代码行数:103,代码来源:installer.py

示例7: Path

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [as 别名]
from utilityclasses import GhostScript,PdfTk,Convert
import os
from unipath import Path
import unittest
import tempfile
from ocrmethods import convert_image
import shutil
from ocrmethods import get_text_from_image

testdir = Path(r"C:\tmp\pdfprocessing\tests")
testdir.chdir()
convert = Convert()



class TestPIL(unittest.TestCase):
    def test_id_times_roman(self):
        convert(r"C:\tmp\pdfprocessing\tests\test_pdf_page_tnr_noimage.pdf",
                r"C:\tmp\pdfprocessing\tests\test_pdf_page_tnr_noimage.tif")


class TestGhostScript(unittest.TestCase):
    def setUp(self):
        self.gs = GhostScript()
        self.testdir = testdir
        self.tempdir = tempfile.TemporaryDirectory()
        # print("creating tempdir: {}".format(os.path.abspath(self.tempdir.name)))

    def test_pdf_to_png(self):
        input_file = os.path.abspath("test_pdf_page_tnr_noimage.pdf")
        output_filename = "test_gs_pdf_to_png.png"
开发者ID:aggerdom,项目名称:pdf-processing-utils,代码行数:33,代码来源:test.py

示例8: ProjectInstaller

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import chdir [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.chdir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。