Skip to content

Commit

Permalink
Merge pull request #39 from elyak123/avoid_redownload_template
Browse files Browse the repository at this point in the history
Avoid redownloading template, update if possible
  • Loading branch information
freakboy3742 committed May 22, 2017
2 parents 02ac790 + 4daec28 commit b51c203
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions briefcase/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import random
import re
import subprocess
import requests
import shutil
import sys
Expand Down Expand Up @@ -148,9 +149,13 @@ def generate_app_template(self):
print(" * Writing application template...")

if self.template is None:
self.template = 'https://github.com/pybee/Python-%s-template.git' % self.platform
template_path = os.path.expanduser('~/.cookiecutters/Python-%s-template' % self.platform)
if os.path.exists(template_path):
self.template = template_path
self.git_pull(template_path)
else:
self.template = 'https://github.com/pybee/Python-%s-template.git' % self.platform
print("Project template: %s" % self.template)

cookiecutter(
self.template,
no_input=True,
Expand All @@ -173,6 +178,17 @@ def generate_app_template(self):
}
)

def git_pull(self, path):
template_name = path.split('/')[-1]
try:
subprocess.check_output(["git", "pull"], stderr=subprocess.STDOUT, cwd=path)
print('Template %s succesfully updated.' % template_name)
except subprocess.CalledProcessError as pull_error:
error_message = pull_error.output.decode('utf-8')
if 'resolve host' in error_message:
print('Unable to update template %s, using unpulled.' % template_name)
print(error_message)

def install_app_requirements(self):
print(" * Installing requirements...")
if self.distribution.install_requires:
Expand Down

0 comments on commit b51c203

Please sign in to comment.