4
4
5
5
from __future__ import unicode_literals , print_function
6
6
import io
7
+ import tempfile
7
8
from contextlib import contextmanager
8
9
import glob
9
10
import json
10
11
import os
11
12
import sys
12
13
import shutil
13
14
import subprocess
14
- import io
15
15
import colorama
16
16
17
17
from nikola import utils
20
20
21
21
BASE_URL = "https://themes.getnikola.com/v7/"
22
22
23
+
23
24
def error (msg ):
24
25
print (colorama .Fore .RED + "ERROR:" + msg )
25
26
27
+
26
28
def theme_list ():
27
29
return sorted (['base' , 'base-jinja' , 'bootstrap3' , 'bootstrap3-jinja' ] + [theme .split ('/' )[- 1 ] for theme in glob .glob ("v7/*" )])
28
30
31
+
29
32
def build_theme (theme = None ):
30
33
if theme is None : # Check them all
31
34
print ("\n Building all themes\n " )
@@ -47,9 +50,20 @@ def build_theme(theme=None):
47
50
if not os .path .isdir (os .path .join ("output" , "v7" )):
48
51
os .mkdir (os .path .join ("output" , "v7" ))
49
52
50
- if os .path .isdir ('v7/' + theme ):
53
+ if os .path .isdir ('v7/' + theme ):
51
54
with cd ('v7/' ):
55
+ # If there is a .git file, move it away for a while (Issues #72 and #76)
56
+ if os .path .exists (os .path .join (theme , '.git' )):
57
+ has_tmp = True
58
+ tmpdir = tempfile .mkdtemp ()
59
+ shutil .move (os .path .join (theme , '.git' ), os .path .join (tmpdir , 'git-bkp' ))
60
+ else :
61
+ has_tmp = False
62
+
52
63
subprocess .check_call ('zip -r ../output/v7/{0}.zip {0}' .format (theme ), stdout = subprocess .PIPE , shell = True )
64
+ if has_tmp :
65
+ shutil .move (os .path .join (tmpdir , 'git-bkp' ), os .path .join (theme , '.git' ))
66
+ os .rmdir (tmpdir )
53
67
subprocess .check_call ('capty output/v7/{0}/index.html output/v7/{0}.jpg' .format (theme ), stdout = subprocess .PIPE , shell = True )
54
68
55
69
themes_dict = {}
@@ -81,6 +95,7 @@ def init_theme(theme):
81
95
with io .open (conf_path , "a" , encoding = "utf-8" ) as conf :
82
96
conf .write (u"\n \n {2}\n \n THEME = '{0}'\n \n USE_BUNDLES = False\n \n OUTPUT_FOLDER = '{1}'\n \n SOCIAL_BUTTONS_CODE = ''\n USE_BASE_TAG = False\n " .format (theme , o_path , extra_conf ))
83
97
98
+
84
99
@contextmanager
85
100
def cd (path ):
86
101
old_dir = os .getcwd ()
0 commit comments