Skip to content

Commit

Permalink
added stuff!!
Browse files Browse the repository at this point in the history
  • Loading branch information
nficano committed Jul 31, 2011
1 parent 35af6dc commit 062f42b
Show file tree
Hide file tree
Showing 23 changed files with 106 additions and 63 deletions.
6 changes: 4 additions & 2 deletions apps/packages/views.py
Expand Up @@ -10,12 +10,14 @@ def build(request):
List all packages available for build List all packages available for build
""" """
packages = Package.objects.all() packages = Package.objects.all()

if request.method == "POST": if request.method == "POST":
preference_form = PreferenceForm(request.POST) preference_form = PreferenceForm(request.POST)
package_form = PackageForm(request.POST) package_form = PackageForm(request.POST)
if package_form.is_valid() and preference_form.is_valid(): if package_form.is_valid() and preference_form.is_valid():
packages = package_form.cleaned_data['packages'] req_pkg = package_form.cleaned_data['packages']
req_pkg = [p.canonical for p in packages]

name = preference_form.cleaned_data['name'] name = preference_form.cleaned_data['name']
else: else:
package_form = PackageForm() package_form = PackageForm()
Expand Down
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.
2 changes: 2 additions & 0 deletions apps/vinegar/base/assets/setup.cfg
@@ -0,0 +1,2 @@
[project]
name: {{ project_name }}
38 changes: 25 additions & 13 deletions src/vinegar/bootstrap.py → apps/vinegar/base/pickleback.py
Expand Up @@ -2,14 +2,34 @@
import sys import sys
import os import os
import subprocess import subprocess
import shutil


Config = ConfigParser.ConfigParser()
Config.read('setup.cfg')
join = lambda a,*p: os.path.abspath(os.path.join(a,*p)) join = lambda a,*p: os.path.abspath(os.path.join(a,*p))

WORKING_DIR = os.path.abspath(os.path.dirname(__file__))
ASSETS_DIR = join(WORKING_DIR, 'assets')
CONF_FILE = os.path.join(ASSETS_DIR, 'setup.cfg')
BASE_PROJECT_DIR = join(ASSETS_DIR, 'project')

Config = ConfigParser.ConfigParser()
Config.read(CONF_FILE)

PROJECT_NAME = Config.get('project','name') PROJECT_NAME = Config.get('project','name')


def main(argv): def main(argv):
create_virtualenv(PROJECT_NAME) bin_path = create_virtualenv(PROJECT_NAME)
project_dir = create_project(PROJECT_NAME)

pip_requirements = os.path.join(ASSETS_DIR,'requirements.txt')
with open(pip_requirements,'r') as fh:
lines = fh.readlines()
for pkg in lines:
pip(bin_path, package_name=pkg)

def create_project(project_name):
project = join(WORKING_DIR, project_name)
shutil.copytree(BASE_PROJECT_DIR, project)
return project


def detect_active_virtualenv(): def detect_active_virtualenv():
""" check if a virtualenv is currently activated """ """ check if a virtualenv is currently activated """
Expand All @@ -26,7 +46,6 @@ def create_virtualenv(project_name):
import virtualenv import virtualenv
workon_path = get_virtualenv_path() workon_path = get_virtualenv_path()
home_path = join(workon_path, project_name) home_path = join(workon_path, project_name)
working_dir = os.path.abspath(os.path.dirname(__file__))


virtualenv.create_environment(home_path, site_packages=False, clear=True) virtualenv.create_environment(home_path, site_packages=False, clear=True)


Expand All @@ -37,10 +56,10 @@ def create_virtualenv(project_name):


bin_path = join(home_path, bin_dirname) bin_path = join(home_path, bin_dirname)
activate_virtualenv(bin_path) activate_virtualenv(bin_path)
base_req = os.path.join(working_dir, 'base-requirements.txt') base_req = os.path.join(ASSETS_DIR, 'base-requirements.txt')
easy_install(bin_path, 'pip') easy_install(bin_path, 'pip')
pip(bin_path, req_file=base_req) pip(bin_path, req_file=base_req)
django_init(bin_path, PROJECT_NAME) return bin_path


def easy_install(bin_path, package_name): def easy_install(bin_path, package_name):
f = os.path.join(bin_path, 'easy_install') f = os.path.join(bin_path, 'easy_install')
Expand Down Expand Up @@ -72,12 +91,5 @@ def activate_virtualenv(bin_path):
sys.path.remove(item) sys.path.remove(item)
sys.path[:0] = new_sys_path sys.path[:0] = new_sys_path


def clean_up(bin_path):
pass

def django_init(bin_path, project_name=PROJECT_NAME):
f = os.path.join(bin_path, 'django-admin.py')
subprocess.call([f, 'startproject', project_name])

if __name__ == '__main__': if __name__ == '__main__':
main(sys.argv[1:]) main(sys.argv[1:])
30 changes: 30 additions & 0 deletions apps/vinegar/build_package.py
@@ -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
45 changes: 45 additions & 0 deletions apps/vinegar/setup_project.py
@@ -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.
1 change: 0 additions & 1 deletion core/models.py

This file was deleted.

File renamed without changes.
Empty file removed src/project_template/__init__.py
Empty file.
Empty file.
45 changes: 0 additions & 45 deletions src/project_template/local_settings.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/vinegar/setup.cfg

This file was deleted.

0 comments on commit 062f42b

Please sign in to comment.