Permalink
Browse files

added stuff!!

  • Loading branch information...
1 parent 35af6dc commit 062f42b59721dd106a91a4a49d2d19f31700b957 @nficano nficano committed Jul 31, 2011
View
@@ -10,12 +10,14 @@ def build(request):
List all packages available for build
"""
packages = Package.objects.all()
-
+
if request.method == "POST":
preference_form = PreferenceForm(request.POST)
package_form = PackageForm(request.POST)
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']
else:
package_form = PackageForm()
File renamed without changes.
@@ -0,0 +1,2 @@
+[project]
+name: {{ project_name }}
@@ -2,14 +2,34 @@
import sys
import os
import subprocess
+import shutil
-Config = ConfigParser.ConfigParser()
-Config.read('setup.cfg')
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')
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():
""" check if a virtualenv is currently activated """
@@ -26,7 +46,6 @@ def create_virtualenv(project_name):
import virtualenv
workon_path = get_virtualenv_path()
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)
@@ -37,10 +56,10 @@ def create_virtualenv(project_name):
bin_path = join(home_path, bin_dirname)
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')
pip(bin_path, req_file=base_req)
- django_init(bin_path, PROJECT_NAME)
+ return bin_path
def easy_install(bin_path, package_name):
f = os.path.join(bin_path, 'easy_install')
@@ -72,12 +91,5 @@ def activate_virtualenv(bin_path):
sys.path.remove(item)
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__':
main(sys.argv[1:])
@@ -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
@@ -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.
View
@@ -1 +0,0 @@
-# django needs this file
File renamed without changes.
No changes.
No changes.
@@ -1,45 +0,0 @@
-from settings import INSTALLED_APPS, MIDDLEWARE_CLASSES
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': '', # Or path to database file if using sqlite3.
- 'USER': '', # Not used with sqlite3.
- 'PASSWORD': '', # Not used with sqlite3.
- 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
- 'PORT': '', # Set to empty string for default. Not used with sqlite3.
- }
-}
-
-# django debug toolbar
-
-INTERNAL_IPS = (
- '127.0.0.1',
-)
-
-MIDDLEWARE_CLASSES += (
- 'debug_toolbar.middleware.DebugToolbarMiddleware',
-)
-
-INSTALLED_APPS += (
- 'debug_toolbar',
-)
-
-DEBUG_TOOLBAR_PANELS = (
- 'debug_toolbar.panels.version.VersionDebugPanel',
- 'debug_toolbar.panels.timer.TimerDebugPanel',
- 'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
- 'debug_toolbar.panels.headers.HeaderDebugPanel',
- 'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
- 'debug_toolbar.panels.template.TemplateDebugPanel',
- 'debug_toolbar.panels.sql.SQLDebugPanel',
- 'debug_toolbar.panels.signals.SignalDebugPanel',
- 'debug_toolbar.panels.logger.LoggingPanel',
-)
-
-DEBUG_TOOLBAR_CONFIG = {
- 'INTERCEPT_REDIRECTS': False,
-}
View
@@ -1,2 +0,0 @@
-[project]
-name: myblog

0 comments on commit 062f42b

Please sign in to comment.