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

Last change on this file since 1223 was 1223, checked in by ezyang, 13 years ago
Merge scriptsdev changes from trunk (in practice, it should be the other way around).
  • Property svn:executable set to *
File size: 3.6 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
19sys.path.insert(0, "/mit/$USER/Scripts/django")
20os.chdir("/mit/$USER/Scripts/django/$name")
21os.environ['DJANGO_SETTINGS_MODULE'] = "$name.settings"
22
23from django.core.servers.fastcgi import runfastcgi
24runfastcgi(method="threaded", daemonize="false")
25EOF
26close FASTCGI;
27chmod 0755, "index.fcgi";
28
29open HTACCESS, ">.htaccess";
30print HTACCESS <<EOF;
31RewriteEngine On
32RewriteCond %{REQUEST_FILENAME} !-f
33RewriteCond %{REQUEST_FILENAME} !-d
34RewriteRule ^(.*)\$ index.fcgi/\$1 [QSA,L]
35EOF
36close HTACCESS;
37chmod 0777, ".htaccess";
38
39chdir "/mit/$USER/Scripts/django/";
40system qw{django-admin.py startproject}, $name;
41chdir "$name";
42
43open SETTINGS, "settings.py";
44open NEWSETTINGS, ">settings.py.new";
45while (<SETTINGS>) {
46  chomp;
47  if (/Your Name/) {
48    $_ = "    ('$USER', '$email'),";
49  } elsif (/^DATABASE_ENGINE/) {
50    $_ = "DATABASE_ENGINE = 'mysql'";
51  } elsif  (/^DATABASE_NAME/) {
52    $_ = "DATABASE_NAME = '$sqldb'";
53  } elsif (/^DATABASE_USER/) {
54    $_ = "DATABASE_USER = '$sqluser'";
55  } elsif (/^DATABASE_PASSWORD/) {
56    $_ = "DATABASE_PASSWORD = '$sqlpass'";
57  } elsif (/^DATABASE_HOST/) {
58    $_ = "DATABASE_HOST = '$sqlhost'";
59  } elsif (/Chicago/) {
60    $_ =~ s/Chicago/New_York/;
61  } elsif (/^ADMIN_MEDIA_PREFIX/) {
62    $_ = "ADMIN_MEDIA_PREFIX = '/__scripts/django/media/'";
63  } elsif (/^INSTALLED_APPS/) {
64    print NEWSETTINGS "$_\n";
65    while (<SETTINGS>) {
66      if (/^\)/) {
67        print NEWSETTINGS "    'django.contrib.admin',\n";
68        print NEWSETTINGS "    'django.contrib.admindocs',\n";
69      }
70      print NEWSETTINGS $_;
71    }
72  }
73  print NEWSETTINGS "$_\n";
74}
75close NEWSETTINGS;
76close SETTNGS;
77rename "settings.py.new", "settings.py";
78
79open URLS, "urls.py";
80open NEWURLS, ">urls.py.new";
81while (<URLS>) {
82  chomp;
83  if (/^#.*from django\.contrib import admin/) {
84    $_ =~ s/^# *//;
85  } elsif (/^#.*admin.autodiscover/) {
86    $_ =~ s/^# *//;
87  } elsif (/^ *# *\(r\'\^admin\//) {
88    $_ =~ s/# *//;
89  }
90  print NEWURLS "$_\n";
91}
92close NEWURLS;
93close URLS;
94rename "urls.py.new", "urls.py";
95
96print "Initializing your project's SQL database schema...\n";
97system qw{./manage.py syncdb --noinput};
98print "...done\n";
99
100print "Creating your superuser account... ";
101system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput";
102print "done\n";
103print "Setting your superuser password... ";
104system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'";
105print "done\n";
106
107print "\nDjango has been installed. The setup is roughly what's described\n";
108print "in the shared-hosting section of\n";
109print "  http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n";
110print "We've also enabled the admin app. You can start from the 'Creating\n";
111print "models' step of the Django tutorial:\n";
112print "  http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n";
113print "Your project is located in:\n";
114print "  /mit/$USER/Scripts/django/$name/\n";
115print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
116print "When you edit your code, run the command\n";
117print "  touch /mit/$USER/web_scripts/$addrend/index.fcgi\n";
118print "before testing, to cause your site to reload the new code.\n";
119press_enter;
120
121exit 0;
Note: See TracBrowser for help on using the repository browser.