source: branches/locker-dev/locker/deploy/bin/django @ 2075

Last change on this file since 2075 was 2074, checked in by andersk, 11 years ago
Merge r2072:2073 from trunk/locker to branches/locker-dev/locker This is effectively a noop, but contains a different conflict resolution for the svn:mergeinfo property on locker/bin/crontab in an attempt to restore sanity and avoid future conflicts. Ha.
File size: 3.7 KB
Line 
1#!/usr/bin/perl
2use strict;
3use FindBin qw($Bin);
4use lib $Bin;
5use onserver;
6
7setup();
8
9print "\nEnter the code name for your project (a valid Python package name).\n";
10print "Do not use 'django' or the name of any other Python library.\n";
11print "Project name: ";
12my $name = <STDIN>;
13chomp $name;
14
15open FASTCGI, ">index.fcgi";
16print FASTCGI <<EOF;
17#!/usr/bin/env python
18import sys, os, time, threading, django.utils.autoreload
19sys.path.insert(0, "/mit/$USER/Scripts/django")
20os.chdir("/mit/$USER/Scripts/django/$name")
21os.environ['DJANGO_SETTINGS_MODULE'] = "$name.settings"
22
23def reloader_thread():
24  while True:
25    if django.utils.autoreload.code_changed():
26      os._exit(3)
27    time.sleep(1)
28t = threading.Thread(target=reloader_thread)
29t.daemon = True
30t.start()
31
32from django.core.servers.fastcgi import runfastcgi
33runfastcgi(method="threaded", daemonize="false")
34EOF
35close FASTCGI;
36chmod 0755, "index.fcgi";
37
38open HTACCESS, ">.htaccess";
39print HTACCESS <<EOF;
40RewriteEngine On
41
42RewriteRule ^\$ index.fcgi/ [QSA,L]
43
44RewriteCond %{REQUEST_FILENAME} !-f
45RewriteCond %{REQUEST_FILENAME} !-d
46RewriteRule ^(.*)\$ index.fcgi/\$1 [QSA,L]
47EOF
48close HTACCESS;
49chmod 0777, ".htaccess";
50
51chdir "/mit/$USER/Scripts/django/";
52system(qw{django-admin startproject}, $name)==0 or die "\nFailed to create app.\n\n";
53chdir "$name";
54
55open SETTINGS, "settings.py";
56open NEWSETTINGS, ">settings.py.new";
57while (<SETTINGS>) {
58  chomp;
59  if (/Your Name/) {
60    $_ = "    ('$USER', '$email'),";
61  } elsif (/'ENGINE'/) {
62    $_ = "        'ENGINE': 'django.db.backends.mysql',";
63  } elsif  (/'NAME'/) {
64    $_ = "        'NAME': '$sqldb',";
65  } elsif (/'USER'/) {
66    $_ = "        'USER': '$sqluser',";
67  } elsif (/'PASSWORD'/) {
68    $_ = "        'PASSWORD': '$sqlpass',";
69  } elsif (/'HOST'/) {
70    $_ = "        'HOST': '$sqlhost',";
71  } elsif (/Chicago/) {
72    $_ =~ s/Chicago/New_York/;
73  } elsif (/^ADMIN_MEDIA_PREFIX/) {
74    $_ = "ADMIN_MEDIA_PREFIX = '/__scripts/django/media/'";
75  } elsif (/^INSTALLED_APPS/) {
76    print NEWSETTINGS "$_\n";
77    while (<SETTINGS>) {
78      if (/^\)/) {
79        print NEWSETTINGS "    'django.contrib.admin',\n";
80        print NEWSETTINGS "    'django.contrib.admindocs',\n";
81      }
82      print NEWSETTINGS $_;
83    }
84  }
85  print NEWSETTINGS "$_\n";
86}
87close NEWSETTINGS;
88close SETTNGS;
89rename "settings.py.new", "settings.py";
90
91open URLS, "urls.py";
92open NEWURLS, ">urls.py.new";
93while (<URLS>) {
94  chomp;
95  if (/^#.*from django\.contrib import admin/) {
96    $_ =~ s/^# *//;
97  } elsif (/^#.*admin.autodiscover/) {
98    $_ =~ s/^# *//;
99  } elsif (/^ *# *\(r\'\^admin\//) {
100    $_ =~ s/# *//;
101  }
102  print NEWURLS "$_\n";
103}
104close NEWURLS;
105close URLS;
106rename "urls.py.new", "urls.py";
107
108print "Initializing your project's SQL database schema...\n";
109system qw{./manage.py syncdb --noinput};
110print "...done\n";
111
112print "Creating your superuser account... ";
113system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput";
114print "done\n";
115print "Setting your superuser password... ";
116system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'";
117print "done\n";
118
119print "\nDjango has been installed. The setup is roughly what's described\n";
120print "in the shared-hosting section of\n";
121print "  http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n";
122print "We've also enabled the admin app. You can start from the 'Creating\n";
123print "models' step of the Django tutorial:\n";
124print "  http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n";
125print "Your project is located in:\n";
126print "  /mit/$USER/Scripts/django/$name/\n";
127print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
128press_enter;
129
130exit 0;
Note: See TracBrowser for help on using the repository browser.