/
init-content.py
67 lines (54 loc) · 1.72 KB
/
init-content.py
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
61
62
63
64
65
66
67
#!/usr/bin/env python3
# init-content.py - Set up GitAtom content structure.
import os
from pathlib import Path
import shutil
import sys
import yaml
from gitatom import build
from gitatom.config import publish_directory
# Write a default config file.
def generate_default_config(path):
yaml_dict = {
'feed_id' : 'feed id',
'feed_title' : 'feed title',
'author' : 'author',
'repo_path' : 'path to bare git repository',
'work_path' : 'path to work tree',
'host' : 'host ip address',
'port' : 'port number',
'username' : 'username',
'keypath' : 'path to ssh key',
'deploy' : False
}
with open(path, 'w') as f:
yaml.dump(yaml_dict, f, sort_keys=False)
#create the initial structure in local for hook and main to work with
content_path = Path('./content/')
if content_path.exists():
print("./content: exists, giving up", file=sys.stderr)
exit(1)
content_path.mkdir()
generate_default_config('./content/config.yaml')
publish_path = Path(f'./content/{publish_directory}')
posts_path = publish_path / 'posts'
posts_path.mkdir(parents=True)
atoms_path = Path('./content/atoms')
atoms_path.mkdir()
markdowns_path = Path('./content/markdowns')
markdowns_path.mkdir()
build.create(publish_path)
shutil.copytree("gitatom/templates/", "./content/templates")
shutil.move("./content/templates/style.css", publish_path)
shutil.move("./content/templates/feed-icon.png", publish_path)
# Set up the content repo.
wstatus = os.system("""sh -c '
cd content &&
git init &&
git add . &&
git commit -m "my blog, by GitAtom"'
""")
code = os.waitstatus_to_exitcode(wstatus)
if code != 0:
print("content: repo creation failed, giving up.", file=sys.stderr)
exit(1)