Update of /cvsroot/tmda/tmda/contrib/cgi
In directory sc8-pr-cvs1:/tmp/cvs-serv17768
Modified Files:
compile
Log Message:
Added help, configuration switches, and better feedback as to what is going on.
Index: compile
===================================================================
RCS file: /cvsroot/tmda/tmda/contrib/cgi/compile,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- compile 28 Nov 2002 17:08:12 -0000 1.1
+++ compile 29 Nov 2002 17:08:14 -0000 1.2
@@ -1,5 +1,5 @@
#!/usr/bin/env python
-
+#
# Copyright (C) 2002 Gre7g Luterman <[EMAIL PROTECTED]>
#
# This file is part of TMDA.
@@ -19,42 +19,105 @@
# along with TMDA; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Pending queue manipulation tool.
+
+Usage: %(Program)s [OPTIONS]
+
+Where:
+ -c <file>
+ --config-file <file>
+ Specify a different configuration file other than ~/.tmda/config.
+
+ -h
+ --help
+ Print this help message and exit.
+
+ -n
+ --no-su
+ Compile a CGI to run in no-su mode.
+
+ -t <file>
+ --target <file>
+ Compile as a file other than ./tmda-cgi.
+
+By default, this program compiles tmda-cgi in the current directory and sets
+the program to run as the user who compiled it. If that user is root, the
+resulting CGI will run in system-wide mode. Otherwise it will run in single-
+user mode. You may optionally specify the -n option to compile for no-su mode.
+
+The target may be specified on the command line with the -t option.
+
+Use the -c option to specify a different location for your TMDA configuration
+file. You may use a "~" anywhere in the path to specify "the current user".
+For example:
+
+ %(Program)s -c /var/tmda/~/config
+
+Will look for configuration files at /var/tmda/<user>/config instead of the
+usual ~<user>/.tmda/config.
+
+If no ~ is specified, compile will make a "best guess".
+"""
+
+import getopt
import os
import string
import sys
+Program = sys.argv[0]
+Target = "tmda-cgi"
+Perm = 04755
+
+def Usage(Code, Msg=""):
+ print __doc__ % globals()
+ if Msg: print Msg
+ sys.exit(Code)
+
+try:
+ Opts, Args = getopt.getopt(sys.argv[1:], "c:nht:",
+ ["config-file=", "help", "no-su", "target="])
+except getopt.error, Msg:
+ Usage(1, Msg)
+
+for Opt, Arg in Opts:
+ if Opt in ("-h", "--help"):
+ Usage(0)
+ elif Opt in ('-c', '--config-file'):
+ os.environ['TMDARC'] = Arg
+ elif Opt in ('-t', '--target'):
+ Target = Arg
+ elif Opt in ('-n', '--no-su'):
+ Perm = 0755
+
# Create dirs.h
F = open("dirs.h", "w")
F.write("""#define PYTHON "%s"
#define INSTALL "%s"
""" % (sys.executable, os.getcwd()))
if os.environ.has_key("TMDARC"):
- TMDARC = \
- string.replace(os.environ["TMDARC"], "/%s/" % os.environ["USER"], "/~/")
- F.write("""#define TMDARC "%s"
-""" % TMDARC)
- print """NOTE: User configuration files have been relocated by setting TMDARC.
+ TMDARC = os.environ["TMDARC"]
+ if TMDARC.find("~") < 0:
+ TMDARC = string.replace(TMDARC, "/%s/" % os.environ["USER"], "/~/")
+ print """NOTE:
tmda-cgi will look for config files at: %s
Where <user> will be replaced by the user's login name.
-""" % string.replace(os.environ["TMDARC"], "/%s/" % os.environ["USER"],
- "/<user>/")
+""" % string.replace(TMDARC, "/~/", "/<user>/")
+ F.write("""#define TMDARC "%s"
+""" % TMDARC)
F.close()
# Remove any old tmda-rc
try:
- os.unlink("tmda-cgi")
+ os.unlink(Target)
except: pass
# Compile tmda-cgi
-os.system("gcc tmda-cgi.c -o tmda-cgi")
+os.system("gcc tmda-cgi.c -o %s" % Target)
# Remove dirs.h
os.unlink("dirs.h")
-# Build no-su?
-if (len(sys.argv) > 1) and (sys.argv[1] == "no-su"):
- os.chmod("tmda-cgi", 0755)
-else:
- os.chmod("tmda-cgi", 04755)
+# Set permissions
+os.chmod(Target, Perm)
print "Compilation done."
_______________________________________
tmda-cvs mailing list
http://tmda.net/lists/listinfo/tmda-cvs