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


Python Path.write_file方法代码示例

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


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

示例1: add_deployment

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def add_deployment(directory, name, templates_dir='templates', deployment_dir='deployment', mode=0777):
    """ Adds new deployment if not exists
    """
    context = {
        'datetime': datetime.datetime.now(),
        'name': name,
        'project_name': get_project_name(directory)
    }

    dd, df = get_deployment_info(directory, name)

    if df.exists():
        raise ExistingDeploymentError()

    # create deployments directory
    df.parent.mkdir(parents=True, mode=mode)

    # write deployment file
    df.write_file(
        get_rendered_template('deployment.py', context)
    )
    top_td = Path(__file__).parent.child(templates_dir)
    td = top_td.child(deployment_dir)
    for tf in td.walk():
        if tf.isdir():
            continue
        partitioned = tf.partition(td)
        target = Path(dd, Path(partitioned[2][1:]))
        target_dir = target.parent
        if not target_dir.exists():
            target_dir.mkdir(parents=True, mode=mode)
        tmp = tf.partition(top_td)[2][1:]
        rendered = get_rendered_template(tmp, context)
        target.write_file(rendered)
开发者ID:phonkee,项目名称:easyfab,代码行数:36,代码来源:commands.py

示例2: test_load_directionals_no_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [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

示例3: test_load_street_types_no_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [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

示例4: test_load_states_space_end_of_line

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [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

示例5: process

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def process(appname):
    appdir = Path(appname)
    if not appdir.isdir():
        print("Error: there is no app called {0}.".format(appdir))
        sys.exit(1)
    # else
    static = Path(appname, 'static', appname)
    static.mkdir(True)
    templates = Path(appname, 'templates', appname)
    templates.mkdir(True)
    urls = Path(appname, 'urls.py')
    if not urls.isfile():
        urls.write_file(urls_py)
开发者ID:jabbalaci,项目名称:django-hello_project,代码行数:15,代码来源:init_app.py

示例6: create

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
    def create(self, entity):
        repo_file = Path(self.path, 'conf/repos/%s.conf' % entity)
        if repo_file.exists():
            raise ValueError('Repository %s already exists' % entity)
        # If there are missing parent paths in the repo path, create them so we don't get IOErrors
        # In the case of a repo having names with slashes (e.g. "username/reponame")
        elif repo_file.parent != Path(""):
            repo_file.parent.mkdir(parents=True)

        repo_file.write_file("repo %s\n" % entity)

        self.git.commit([str(repo_file)], 'Created repo %s' % entity)

        return Repository(entity, self.path, self.git)
开发者ID:PressLabs,项目名称:pyolite,代码行数:16,代码来源:repository.py

示例7: create_file

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
    def create_file(self, which_one):
        self.render_config_for_file_template(which_one=which_one)

        logger.info('Creating config files in parent dir: %s'
                    % self.install_path)

        #gets self.postdeactivate if which_one=postdeactivate
        contents = getattr(self, which_one)

        logger.info('%s: Writing contents to file ...' % which_one)

        p = Path(self.install_path, which_one)
        #write configuration and append it to the file
        p.write_file(contents, 'a+')
        logger.info('...done')
开发者ID:Libermentix,项目名称:project_installer,代码行数:17,代码来源:installer.py

示例8: join_file

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def join_file(path, output_file_name=None, chunk_size='1K'):
    path = Path(path)
    chunk_size = get_real_size(chunk_size)
    if output_file_name is None:
        output_file_path = create_file_name(path)
    else:
        output_file_path = Path(output_file_name)

    output_file_path.write_file(b'', 'wb')

    with open(output_file_path, 'wb') as output_file:
        for cur_file_name in files_iter(path):
            with open(cur_file_name, 'rb') as cur_file:
                for piece in read_in_chunks(cur_file, chunk_size):
                    output_file.write(piece)
开发者ID:zokis,项目名称:zsplitjoin,代码行数:17,代码来源:join_files.py

示例9: get_thesaurus_text

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def get_thesaurus_text():
    p = Path('./thesaurus.txt')
    
    text = None
    
    if not p.exists():
        logging.info("File doesn't exist, parsing from internet")
        text = _retrieve_thesaurus_text()
        p.write_file(text.encode('utf-8')) 
    else:
        logging.info("File exists, reading in")
        text = p.read_file().decode('utf-8')
    
    logging.info("Read text length: %s" % len(text))

    return text
开发者ID:jimmytheleaf,项目名称:ThesaurusGame,代码行数:18,代码来源:thesaurus.py

示例10: generate_thumbnail

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def generate_thumbnail(obj, image_field='logo'):
    source = getattr(obj, image_field)

    source_img = Path(source.path)

    parent_dir = source_img.parent

    target_img = Path(
        parent_dir, source_img.stem + THUMBNAIL_SUFFIX + source_img.ext
    )

    source_img_open = open(source_img)

    image_generator = Thumbnail(source=source_img_open)
    resized_image = image_generator.generate()

    target_img.write_file(resized_image.read())
开发者ID:EuTM,项目名称:madeineuregio.com,代码行数:19,代码来源:generators.py

示例11: unused_write_release_notes

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def unused_write_release_notes():
    """
    Generate docs/releases/x.y.z.rst file from setup_info.
    """
    v = env.SETUP_INFO['version']
    if v.endswith('+'):
        return
    notes = Path(env.ROOTDIR, 'docs', 'releases', '%s.rst' % v)
    if notes.exists():
        return
    must_confirm("Create %s" % notes.absolute())
    #~ context = dict(date=get_current_date().strftime(env.long_date_format))
    context = dict(date=get_current_date().strftime('%Y%m%d'))
    context.update(env.SETUP_INFO)
    txt = """\
==========================
Version %(version)s
==========================

Release process started :blogref:`%(date)s`


List of changes
===============

New features
------------

Optimizations
-------------

Bugfixes
--------

Manual tasks after upgrade
--------------------------


""" % context
    notes.write_file(txt)
    notes.parent.child('index.rst').set_times()
    args = [os.environ['EDITOR']]
    args += [notes.absolute()]
    local(' '.join(args))
开发者ID:ManuelWeidmann,项目名称:atelier,代码行数:46,代码来源:fablib.py

示例12: move_to_venv

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
    def move_to_venv(self, which_one):
        """
        Moves the created config_files into the bin folder to be executed.
        Does this by first pasting all the contents of the temporary file
        into the new or existing target file and then deleting the temp file.
        """
        target = Path(self.venv_folder, self.project_name, 'bin', which_one)
        source = Path(self.install_path, which_one)
        logger.info('target: %s, move_orig: %s' % (target, source))

        if source.exists():
            logger.info('Moving %s into place ...' % which_one)
            content = source.read_file()

            #make sure the directory exists
            if not target.parent.exists():
                target.parent.mkdir(parents=True)
            target.write_file(content, 'w+')

            source.remove()

        logger.info('...done')
开发者ID:Libermentix,项目名称:project_installer,代码行数:24,代码来源:installer.py

示例13: append

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
    def append(self, key):
        key_path = Path(key)

        if key_path.isfile():
            with open(str(key_path)) as f:
                key = f.read()

        if key in self:
                return

        directory = Path(self.user.path, 'keydir', self.user.name,
                                         hashlib.md5(key.strip().split()[1]).hexdigest())
        directory.mkdir(parents=True)

        key_file = Path(directory, "%s.pub" % self.user.name)
        if key_file.exists() and key_file.read_file() == key:
                return

        key_file.write_file(key)

        self.user.git.commit(['keydir'],
                                                 'Added new key for user %s' % self.user.name)

        super(ListKeys, self).append(key)
开发者ID:Codevolve,项目名称:pyolite,代码行数:26,代码来源:keys.py

示例14: index

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
def index(notebook):
    #return '<h1>Hello World!</h1>'
    if notebook == None:
    	notebooks_list = db.all();
    	return render_template('index.html', notebooks=notebooks_list)
    else:
		if request.method == 'POST':
			# Check if the notebook already exists
			selected_notebook = db.search(where('slug') == notebook)
			notebook_data = {}

			if selected_notebook:
				notebook_data['title'] = selected_notebook[0].get('title')
				notebook_data['slug'] = selected_notebook[0].get('slig')
				notebook_data['desc'] = selected_notebook[0].get('desc')

				new_md_file = Path(notebooks_dir, notebook + '.md')
				new_md_file.write_file('\n'.join(request.form['content'].split('\r\n')))

				db.update({'desc':request.form['desc'], 'title':request.form['title']}, where('slug') == notebook)
			else:
				notebook_data['title'] = request.form['title']
				notebook_data['slug'] = slugify(request.form['title'])
				notebook_data['desc'] = request.form['desc']
				#notebook_data['content'] = request.form['content'].split('\r\n')
				#Create markdown file under notebooks dir
				new_md_file = Path(notebooks_dir, notebook_data['slug'] + '.md')
				new_md_file.write_file('\n'.join(request.form['content'].split('\r\n')))

				db.insert(notebook_data)
				notebook = notebook_data['slug']

			#return render_template('notebook.html', notebook=notebook_data)
			return redirect(notebook)
		else:
			notebook_data = {}
			notebook_html = ''

			mode = request.args.get('m')
			selected_notebook = db.search(where('slug') == notebook)
			notebook_path = Path(notebooks_dir, notebook + '.md')
			
			if selected_notebook:
				notebook_data['title'] = selected_notebook[0].get('title')
				notebook_data['desc'] = selected_notebook[0].get('desc')
			else:
				notebook_data['title'] = ''
				notebook_data['desc'] = ''
				notebook_data['content'] = ''

			if mode == None:
				if selected_notebook:
					if notebook_path.exists():
						notebook_html = md.markdown(notebook_path.read_file(), extras=["code-friendly", "fenced-code-blocks", "tables", "metadata", "cuddled-lists", "link-patterns"], link_patterns=link_patterns)
						notebook_data['content'] = notebook_html
					#notebook_data['content'] = '\n'.join(selected_notebook[0].get('content'))

				return render_template('notebook.html', notebook=notebook_data)
			else:
				if selected_notebook:
					if notebook_path.exists():
						notebook_html = notebook_path.read_file()
						notebook_data['content'] = notebook_html

				return render_template('notebook-edit.html', notebook=notebook_data)
开发者ID:dewang-mistry,项目名称:Graphite,代码行数:67,代码来源:app.py

示例15: save_file

# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import write_file [as 别名]
 def save_file(self, response):
     p = Path("data/" + response.url.split("/")[-1] + '.html')
     p.write_file(response.body)
开发者ID:jimmytheleaf,项目名称:hwaetbot,代码行数:5,代码来源:crawler.py


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