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

Last change on this file since 1493 was 1414, checked in by ezyang, 15 years ago
Merged in changes from trunk --- Merging r1262 through r1413 into 'deploy/bin': U deploy/bin/django C deploy/bin/rails > Resolved by accepting working copy --- Merging r1221 through r1413 into '.': U sql/bin/get-password U sql/bin/save-password U doc/tickets/rt.txt U doc/tickets/cnames.txt U bin/fix-php-ini C bin/scripts-rails > Resolved by accepting working copy Skipped 'bin/for-each-server' U bin U sbin/parallel-find.pl U sbin/commit-email.pl U sbin/commit-zephyr Summary of conflicts: Tree conflicts: 2 Skipped paths: 1
  • 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, 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
41RewriteCond %{REQUEST_FILENAME} !-f
42RewriteCond %{REQUEST_FILENAME} !-d
43RewriteRule ^(.*)\$ index.fcgi/\$1 [QSA,L]
44EOF
45close HTACCESS;
46chmod 0777, ".htaccess";
47
48chdir "/mit/$USER/Scripts/django/";
49system qw{django-admin startproject}, $name;
50chdir "$name";
51
52open SETTINGS, "settings.py";
53open NEWSETTINGS, ">settings.py.new";
54while (<SETTINGS>) {
55  chomp;
56  if (/Your Name/) {
57    $_ = "    ('$USER', '$email'),";
58  } elsif (/^DATABASE_ENGINE/) {
59    $_ = "DATABASE_ENGINE = 'mysql'";
60  } elsif  (/^DATABASE_NAME/) {
61    $_ = "DATABASE_NAME = '$sqldb'";
62  } elsif (/^DATABASE_USER/) {
63    $_ = "DATABASE_USER = '$sqluser'";
64  } elsif (/^DATABASE_PASSWORD/) {
65    $_ = "DATABASE_PASSWORD = '$sqlpass'";
66  } elsif (/^DATABASE_HOST/) {
67    $_ = "DATABASE_HOST = '$sqlhost'";
68  } elsif (/Chicago/) {
69    $_ =~ s/Chicago/New_York/;
70  } elsif (/^ADMIN_MEDIA_PREFIX/) {
71    $_ = "ADMIN_MEDIA_PREFIX = '/__scripts/django/media/'";
72  } elsif (/^INSTALLED_APPS/) {
73    print NEWSETTINGS "$_\n";
74    while (<SETTINGS>) {
75      if (/^\)/) {
76        print NEWSETTINGS "    'django.contrib.admin',\n";
77        print NEWSETTINGS "    'django.contrib.admindocs',\n";
78      }
79      print NEWSETTINGS $_;
80    }
81  }
82  print NEWSETTINGS "$_\n";
83}
84close NEWSETTINGS;
85close SETTNGS;
86rename "settings.py.new", "settings.py";
87
88open URLS, "urls.py";
89open NEWURLS, ">urls.py.new";
90while (<URLS>) {
91  chomp;
92  if (/^#.*from django\.contrib import admin/) {
93    $_ =~ s/^# *//;
94  } elsif (/^#.*admin.autodiscover/) {
95    $_ =~ s/^# *//;
96  } elsif (/^ *# *\(r\'\^admin\//) {
97    $_ =~ s/# *//;
98  }
99  print NEWURLS "$_\n";
100}
101close NEWURLS;
102close URLS;
103rename "urls.py.new", "urls.py";
104
105print "Initializing your project's SQL database schema...\n";
106system qw{./manage.py syncdb --noinput};
107print "...done\n";
108
109print "Creating your superuser account... ";
110system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput";
111print "done\n";
112print "Setting your superuser password... ";
113system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'";
114print "done\n";
115
116print "\nDjango has been installed. The setup is roughly what's described\n";
117print "in the shared-hosting section of\n";
118print "  http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n";
119print "We've also enabled the admin app. You can start from the 'Creating\n";
120print "models' step of the Django tutorial:\n";
121print "  http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n";
122print "Your project is located in:\n";
123print "  /mit/$USER/Scripts/django/$name/\n";
124print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
125press_enter;
126
127exit 0;
Note: See TracBrowser for help on using the repository browser.