Skip to content

Commit 1cca360

Browse files
committedApr 6, 2016
Fix #72, #76 -- remove .git files from zipballs
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 726cf7b commit 1cca360

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎scripts/build_themes.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
from __future__ import unicode_literals, print_function
66
import io
7+
import tempfile
78
from contextlib import contextmanager
89
import glob
910
import json
1011
import os
1112
import sys
1213
import shutil
1314
import subprocess
14-
import io
1515
import colorama
1616

1717
from nikola import utils
@@ -20,12 +20,15 @@
2020

2121
BASE_URL = "https://themes.getnikola.com/v7/"
2222

23+
2324
def error(msg):
2425
print(colorama.Fore.RED + "ERROR:" + msg)
2526

27+
2628
def theme_list():
2729
return sorted(['base', 'base-jinja', 'bootstrap3', 'bootstrap3-jinja'] + [theme.split('/')[-1] for theme in glob.glob("v7/*")])
2830

31+
2932
def build_theme(theme=None):
3033
if theme is None: # Check them all
3134
print("\nBuilding all themes\n")
@@ -47,9 +50,20 @@ def build_theme(theme=None):
4750
if not os.path.isdir(os.path.join("output", "v7")):
4851
os.mkdir(os.path.join("output", "v7"))
4952

50-
if os.path.isdir('v7/'+theme):
53+
if os.path.isdir('v7/' + theme):
5154
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+
5263
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)
5367
subprocess.check_call('capty output/v7/{0}/index.html output/v7/{0}.jpg'.format(theme), stdout=subprocess.PIPE, shell=True)
5468

5569
themes_dict = {}
@@ -81,6 +95,7 @@ def init_theme(theme):
8195
with io.open(conf_path, "a", encoding="utf-8") as conf:
8296
conf.write(u"\n\n{2}\n\nTHEME = '{0}'\n\nUSE_BUNDLES = False\n\nOUTPUT_FOLDER = '{1}'\n\nSOCIAL_BUTTONS_CODE = ''\nUSE_BASE_TAG = False\n".format(theme, o_path, extra_conf))
8397

98+
8499
@contextmanager
85100
def cd(path):
86101
old_dir = os.getcwd()

0 commit comments

Comments
 (0)
Please sign in to comment.