-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathmake.py
More file actions
60 lines (49 loc) · 1.69 KB
/
Copy pathmake.py
File metadata and controls
60 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Makes an organized git repo of a book folder
"""
from __future__ import print_function
import codecs
from os.path import abspath, dirname
import jinja2
import sh
class NewFilesHandler():
""" NewFilesHandler - templates and copies additional files to book repos
"""
README_FILENAME = 'README.rst'
def __init__(self, book):
self.book = book
package_loader = jinja2.PackageLoader('gitenberg', 'templates')
self.env = jinja2.Environment(loader=package_loader)
def add_new_files(self):
self.template_readme()
self.copy_files()
def template_readme(self):
template = self.env.get_template('README.rst.j2')
readme_text = template.render(
title=self.book.meta.title,
author=self.book.meta.author,
book_id=self.book.book_id
)
readme_path = "{0}/{1}".format(
self.book.local_path,
self.README_FILENAME
)
with codecs.open(readme_path, 'w', 'utf-8') as readme_file:
readme_file.write(readme_text)
def copy_files(self):
""" Copy the LICENSE and CONTRIBUTING files to each folder repo """
files = [u'LICENSE', u'CONTRIBUTING.rst']
this_dir = dirname(abspath(__file__))
for _file in files:
sh.cp(
'{0}/templates/{1}'.format(this_dir, _file),
'{0}/'.format(self.book.local_path)
)
# copy metadata rdf file
sh.cp(
self.book.meta.rdf_path,
'{0}/'.format(self.book.local_path)
)
self.book.meta.dump_file('{0}/metadata.yaml'.format(self.book.local_path))