Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
106 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,2 @@ | |||
[project] | |||
name: {{ project_name }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
import os | |||
import random | |||
import shutil | |||
import sys | |||
import setup_project | |||
import tarfile | |||
|
|||
join = lambda a,*p: os.path.abspath(os.path.join(a,*p)) | |||
WORKING_DIR = os.path.abspath(os.path.dirname(__file__)) | |||
BASE_DIR = join(WORKING_DIR, 'base') | |||
TEMP_DIR = join(WORKING_DIR, 'tmp') | |||
|
|||
def write_requirements(project_dir, packages): | |||
requirements = os.path.join(project_dir, 'requirements.txt') | |||
with open(requirements, 'w') as fh: | |||
fh.write("\n".join(packages)) | |||
|
|||
def compress(project_dir, project_name): | |||
t = tarfile.open(name="%s.tar.gz" % os.path.join(TEMP_DIR,project_name), mode='w:gz') | |||
t.add(project_dir, recursive=False) | |||
t.close() | |||
return os.path.join(TEMP_DIR, "%s.tar.gz" % project_name) | |||
|
|||
def bundle(project_name, packages): | |||
project_dir = join(TEMP_DIR, project_name) | |||
assets_dir = join(project_dir, 'assets') | |||
setup_project.copy_site(project_name, project_dir) | |||
write_requirements(assets_dir, packages) | |||
tar_name = compress(project_dir, project_name) | |||
return tar_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,45 @@ | |||
import os | |||
import random | |||
import re | |||
import shutil | |||
import sys | |||
|
|||
join = lambda a,*p: os.path.abspath(os.path.join(a,*p)) | |||
WORKING_DIR = os.path.abspath(os.path.dirname(__file__)) | |||
PROJECT_DIR = join(WORKING_DIR, 'base') | |||
|
|||
def copy_site(name, destination): | |||
""" | |||
Copies the project_template directory structure. | |||
""" | |||
|
|||
top_dir = destination | |||
os.mkdir(top_dir) | |||
|
|||
project = os.path.abspath(os.path.dirname(__file__)) | |||
template_dir = PROJECT_DIR | |||
|
|||
for d, subdirs, files in os.walk(template_dir): | |||
relative_dir = d[len(template_dir)+1:].replace('project_name', name) | |||
if relative_dir: | |||
os.mkdir(os.path.join(top_dir, relative_dir)) | |||
for subdir in subdirs[:]: | |||
if subdir.startswith('.'): | |||
subdirs.remove(subdir) | |||
for f in files: | |||
path_old = os.path.join(d, f) | |||
path_new = os.path.join(top_dir, relative_dir, f.replace('project_name', name)) | |||
fp_old = open(path_old, 'r') | |||
fp_new = open(path_new, 'w') | |||
fp_new.write(fp_old.read().replace('{{ project_name }}', name).replace('{{ secret_key }}', generate_secret_key())) | |||
fp_old.close() | |||
fp_new.close() | |||
try: | |||
shutil.copymode(path_old, path_new) | |||
except OSError: | |||
sys.stderr.write("Error, something bad happened.") | |||
|
|||
def generate_secret_key(): | |||
c = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)" | |||
return "".join([random.choice(c) for x in xrange(50)]) |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Empty file.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.