source: branches/fc20-dev/locker/deploy/bin/django @ 2783

Last change on this file since 2783 was 2370, checked in by cereslee, 12 years ago
Merged the -r 2369 from locker-dev to trunk
  • Property svn:executable set to *
File size: 3.8 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/$name")
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/$name";
54
55open SETTINGS, "settings.py";
56open NEWSETTINGS, ">settings.py.new";
57while (<SETTINGS>) {
58  chomp;
59  if (/Your Name/) {
60    $_ = "    ('$USER', '$email'),";
61  } elsif (/^DEBUG = /) {
62      $_ =~ s/DEBUG/import os\n\nDEBUG/;
63  } elsif (/'ENGINE'/) {
64    $_ = "        'ENGINE': 'django.db.backends.mysql',";
65  } elsif  (/'NAME'/) {
66    $_ = "        'NAME': '$sqldb',";
67  } elsif (/'USER'/) {
68    $_ = "        'OPTIONS': {\n            'read_default_file' : os.path.expanduser('~/.my.cnf'),\n        },";
69  } elsif (/'PASSWORD'/) {
70      next;
71  } elsif (/'HOST'/) {
72      next;
73  } elsif (/Chicago/) {
74    $_ =~ s/Chicago/New_York/;
75  } elsif (/^ADMIN_MEDIA_PREFIX/) {
76    $_ = "ADMIN_MEDIA_PREFIX = '/__scripts/django/media/'";
77  } elsif (/^INSTALLED_APPS/) {
78    print NEWSETTINGS "$_\n";
79    while (<SETTINGS>) {
80      if (/^\)/) {
81        print NEWSETTINGS "    'django.contrib.admin',\n";
82        print NEWSETTINGS "    'django.contrib.admindocs',\n";
83      }
84      print NEWSETTINGS $_;
85    }
86  }
87  print NEWSETTINGS "$_\n";
88}
89close NEWSETTINGS;
90close SETTNGS;
91rename "settings.py.new", "settings.py";
92
93open URLS, "urls.py";
94open NEWURLS, ">urls.py.new";
95while (<URLS>) {
96  chomp;
97  if (/^#.*from django\.contrib import admin/) {
98    $_ =~ s/^# *//;
99  } elsif (/^#.*admin.autodiscover/) {
100    $_ =~ s/^# *//;
101  } elsif (/^ *# *\(r\'\^admin\//) {
102    $_ =~ s/# *//;
103  }
104  print NEWURLS "$_\n";
105}
106close NEWURLS;
107close URLS;
108rename "urls.py.new", "urls.py";
109
110chdir "..";
111
112print "Initializing your project's SQL database schema...\n";
113system qw{./manage.py syncdb --noinput};
114print "...done\n";
115
116print "Creating your superuser account... ";
117system qw{./manage.py createsuperuser --username}, $admin_username, "--email", $email, "--noinput";
118print "done\n";
119print "Setting your superuser password... ";
120system qw{mysql -D}, "$USER+$addrlast", "-e", "UPDATE auth_user SET password=MD5(\'$admin_password\') WHERE username=\'$admin_username\'";
121print "done\n";
122
123print "\nDjango has been installed. The setup is roughly what's described\n";
124print "in the shared-hosting section of\n";
125print "  http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/\n";
126print "We've also enabled the admin app. You can start from the 'Creating\n";
127print "models' step of the Django tutorial:\n";
128print "  http://docs.djangoproject.com/en/dev/intro/tutorial01/#id3\n\n";
129print "Your project is located in:\n";
130print "  /mit/$USER/Scripts/django/$name/\n";
131print "To access manage.py, run 'ssh -k $USER\@scripts' and cd to the above directory.\n\n";
132press_enter;
133
134exit 0;
Note: See TracBrowser for help on using the repository browser.