[squeak-dev] [OT] Perl or Python to start an image?
Chris Cunnington
smalltalktelevision at gmail.com
Wed Jan 23 23:11:55 UTC 2013
What is the best language for starting an image? I have two programs
here: one in perl [1]; and, the other in python [2]. The perl works. The
python does not. Both are attempts to write an "external rewriting
program" for Apache [3]
The aim of the program is to isolate a subdomain from a request; use it
to return a port number from a list of subdomains; check to see if the
port is open with netcat; if closed, start an image on the port number
and then print the port number; if open, print the port number. Both
programs turn off buffering.
I have no idea what type lives in $_ and I don't seem to have to care.
With the python, whatever type readline() is putting into the variable
input, I can neither concatenate nor format with another string. Every
step produces some wrinkle I do not see.
I finally fed input into netcat by adding '\r'. The reason the input
variable cannot be formatted into a string and then fed to Popen defies
me utterly.
What's going on? I mean, I could use the perl program, but sort of want
to invest in python.
Chris
[1]
#!/usr/bin/perl -w
# ERP - External Rewrite Program
# take a subdomain and return a port number
$| = 1;
while(<STDIN>) {
$answer=`nc -z localhost $_`;
if ($answer eq '') {
$path = sprintf("/home/ooplatin/coglinux/lib/squeak/4.0-2585/squeak
-vm display=none /home/ooplatin/squeak.org/Squeak4.4alpha.image
/home/ooplating/dirfarm/%u/startparameters.st&", $_);
system($path);
sleep(3);
print $_;
} else {
print $_;
}
}
[2]
#!/usr/bin/env python
# ERP - External Rewrite Program
# take a subdomain and return a port number
import sys, commands, time, subprocess
while True:
input = sys.stdin.readline()
ncstring = '/usr/bin/nc -z localhost ' + input + '\r'
myoutput = commands.getoutput(ncstring)
if len(myoutput) < 40:
startstring =
"/home/ooplatin/coglinux/lib/squeak/4.0-2585/squeak -vm display-none
/home/ooplatin/squeak.org/Squeak4.4alpha.image
/home/ooplatin/dirfarm/%s/startparams.st&" % (input)
subprocess.Popen(startstring, shell=True, stdout=subprocess.PIPE)
time.sleep(3)
print input
else:
print input
[3]
ServerName www.ooplatin.com
ServerAlias *.ooplatin.com
DocumentRoot /home/ooplatin
RewriteLog /etc/httpd/logs/rewrite_log
RewriteLogLevel 9
RewriteEngine On
TransferLog /home/ooplatin/access_log
ErrorLog /home/ooplatin/error_log
RewriteMap ERP prg:/home/ooplatin/ERP.py
RewriteMap SUBDOMAINS txt:/home/ooplatin/subdomains
RewriteCond %{HTTP_HOST} ^([^.]+)\.ooplatin.com
RewriteRule ^(.*) http://%1.ooplatin.com:${ERP:${SUBDOMAINS:%1}} [P]
More information about the Squeak-dev
mailing list
|