incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 21111 - in incubator/depot/trunk/update: bin src/java/org/apache/depot/update/tool
Date Fri, 11 Jun 2004 20:51:42 GMT
Author: ajack
Date: Fri Jun 11 13:51:42 2004
New Revision: 21111

Added:
   incubator/depot/trunk/update/bin/
   incubator/depot/trunk/update/bin/.svnignore
   incubator/depot/trunk/update/bin/update.py
Modified:
   incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/Tool.java
Log:
1) add Python wrapper
2) add -q to tools (quiet)


Added: incubator/depot/trunk/update/bin/.svnignore
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/bin/.svnignore	Fri Jun 11 13:51:42 2004
@@ -0,0 +1 @@
+*.pyc

Added: incubator/depot/trunk/update/bin/update.py
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/bin/update.py	Fri Jun 11 13:51:42 2004
@@ -0,0 +1,160 @@
+#!/bin/bash
+#
+#   Copyright 2003-2004 The Apache Software Foundation
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+# $Header: /home/cvs/gump/python/gmp.py,v 1.4 2004/04/14 22:12:58 ajack Exp $
+
+"""
+
+  This is the commandline entrypoint into Python Gump as a
+  build system (as opposed to a cronned CI tool).
+  
+  It works similarly to "cvs", as it needs to be given the action
+  to do, and it needs to be run in the correct directory
+  (workspace or project).
+
+"""
+
+import os.path
+import os
+import sys
+import socket
+import time
+from string import split
+
+
+def checkEnvironment():
+    if not os.environ.has_key('DEPOT_HOME'):
+        raise RuntimeError, 'Please set the DEPOT_HOME environment variable to where Apache
Depot is installed.'
+    
+def callJavaCommand(iargs):
+    
+    env={}
+    cp=[]
+    
+    # Original CLASSPATH
+    if os.environ.has_key('CLASSPATH'):
+        cp=split(os.environ['CLASSPATH'],os.pathsep)
+    
+    # Where out jar/code is...
+    depotHome=os.path.abspath(os.environ['DEPOT_HOME'])
+    print depotHome
+    depotJars=os.path.abspath(os.path.join(depotHome,'jars'))
+    print depotJars
+    
+    if os.path.exists(depotJars):
+        for jar in os.listdir(depotJars):
+            if jar.endWith('.jar'):
+                cp.append(os.path.abspath(jar))
+            
+    # New CLASSPATH    
+    env['CLASSPATH'] = os.pathsep.join(cp)
+    
+    #
+    # Actually run the Java command
+    #    
+    return runCommand(	'java org.apache.depot.update.tool.DownloaderTool', 
+                        ' '.join(iargs),
+                        env)
+    
+def runCommand(command,args='',env=None,dir=None,outputFile=None):
+    """ 
+        Run a command, and check the result... 
+    """
+    
+    #    
+    originalCWD=None
+    if dir:     
+        originalCWD=os.getcwd()
+        cwdpath=os.path.abspath(dir)
+        try: 
+            if not os.path.exists(cwdpath): os.makedirs(dir)
+            os.chdir(cwdpath)
+        except Exception, details :
+            raise
+            
+    if env:
+                 # Note: We only override what is given, not everything
+        originalENV={}
+        for envKey in env.iterkeys():
+            try:
+                originalENV[envKey]=os.environ[envKey]
+            except:
+                originalENV[envKey]=''
+            os.environ[envKey]=env[envKey]
+        
+    try:    
+        fullCommand = command + ' ' + args    
+       
+        #print fullCommand
+        #print `env`
+       
+        #
+        # Execute Command & Calculate Exit Code
+        #
+        systemReturn=os.system(fullCommand)
+        
+        if not os.name == 'dos' and not os.name == 'nt':
+            waitcode=systemReturn
+        
+            #
+            # The return code (from system = from wait) is (on Unix):
+            #
+            #    a 16 bit number
+            #    top byte    =    exit status
+            #    low byte    =    signal that killed it
+            #
+            exit_code=(((waitcode & 0xFF00) >> 8) & 0xFF)
+        
+        else:
+            exit_code=systemReturn
+    
+    finally:
+        if originalCWD: os.chdir(originalCWD)        
+        if originalENV:
+            for envKey in originalENV.iterkeys():
+	            os.environ[envKey]=originalENV[envKey]
+
+    return exit_code
+
+
+# static void main()
+if __name__=='__main__':
+
+    args=list(sys.argv)
+    result=0
+    
+    try:
+        checkEnvironment()
+        
+        # The path of this command
+        gmpPath = os.path.abspath(args[0])
+        del args[0]     
+    
+        # Call the Java command with the rest of them
+        callJavaCommand(args)
+
+    except KeyboardInterrupt:    
+        print 'Terminated by user interrupt...'
+        result = 1
+        raise
+        
+    except:    
+        print 'Terminated unintentionally...'
+        result = 1
+        raise
+    
+    # bye!
+    sys.exit(result)

Modified: incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/Tool.java
==============================================================================
--- incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/Tool.java	(original)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/Tool.java	Fri Jun 11
13:51:42 2004
@@ -35,12 +35,14 @@
 public abstract class Tool {
 	private static Option l_debugOption = null;
 	private static Option l_verboseOption = null;
+	private static Option l_quietOption = null;
 	private static Option l_statsOption = null;
 	private static Option l_helpOption = null;
 	private static Option l_versionOption = null;
 	private static Options l_options = null;
 	private static boolean l_debug = false;
 	private static boolean l_verbose = false;
+	private static boolean l_quiet = false;
 	private static boolean l_help = false;
 	private static boolean l_version = false;
 	private static StatisticsMonitor l_statistics = null;
@@ -50,12 +52,14 @@
 		l_helpOption = new Option("h", "help", false, "print help, and exit");
 		l_debugOption = new Option("d", "debug", false, "debug output");
 		l_verboseOption = new Option("v", "verbose", false, "verbose output");
+		l_quietOption = new Option("q", "quiet", false, "quiet output");
 		l_statsOption = new Option("s", "stats", false, "statistics output");
 		l_options = new Options();
 		l_options.addOption(l_helpOption);
 		l_options.addOption(l_versionOption);
 		l_options.addOption(l_debugOption);
 		l_options.addOption(l_verboseOption);
+		l_options.addOption(l_quietOption);
 		l_options.addOption(l_statsOption);
 	}
 	protected Options getOptions() {
@@ -68,7 +72,7 @@
 	protected abstract void init();
 	protected void printVersion() {
 		String version = VersionHelper.getMarker().getLongVersion();
-		System.out.println(getTitle() + " : " + version);
+		System.out.println("Apache Depot " + getTitle() + " : " + version);
 	}
 	protected void printHelp() {
 		printVersion();
@@ -87,7 +91,7 @@
 			l_debug = cmdline.isSet(l_debugOption);
 		} catch (ParseException exp) {
 			System.err.println("Bad Command Line. Reason: " + exp.getMessage());
-			printHelp();
+			getOptions().display();
 			System.exit(1);
 		}
 		return cmdline;
@@ -111,6 +115,12 @@
 		int level = LogConstants.INFO;
 		if (l_verbose || l_debug)
 			level = l_debug ? LogConstants.DEBUG : LogConstants.VERBOSE;
+		if ( l_quiet )
+			level = LogConstants.ERROR;
+		
+		if (!l_quiet )
+			printVersion();
+		
 		Logger logger = Logger.pushContext(level, new StandardLogListener());
 		// Monitor (and store statistics)
 		l_statistics = new StatisticsMonitor();

Mime
View raw message