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 36353 - in incubator/depot/trunk/update: . bin src/java/org/apache/depot/update/tool
Date Fri, 13 Aug 2004 15:28:55 GMT
Author: ajack
Date: Fri Aug 13 08:28:54 2004
New Revision: 36353

Added:
   incubator/depot/trunk/update/depot.py
   incubator/depot/trunk/update/local.env
   incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/ConfigTool.java
Removed:
   incubator/depot/trunk/update/bin/
Log:
1) Forget bin/update.py, let's have ./depot.py 'update' (etc.)
2) Adding a config tool (for viewing config).

Added: incubator/depot/trunk/update/depot.py
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/depot.py	Fri Aug 13 08:28:54 2004
@@ -0,0 +1,234 @@
+#!/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 entry point into Depot Updater
+
+"""
+
+import os.path
+import os
+import sys
+import socket
+import time
+from string import split
+
+class Verbosity:
+    """
+    A simple class to manage logging verbository level
+    """
+    
+    QUIET=0
+    VERBOSE=1
+    DEBUG=2
+    
+    def __init__(self,level=QUIET):
+        self.level=level
+        
+    def setLevel(self,level):
+        self.level=level
+        
+    def isVerbose(self):
+        return self.level >= Verbosity.VERBOSE
+        
+    def isDebug(self):
+        return self.level >= Verbosity.DEBUG
+        
+    def isQuiet(self):
+        return self.level >= Verbosity.QUIET
+
+def checkEnvironment():
+    """
+    Check environment is set correct.
+    """
+    if os.environ.has_key('DEPOT_UPDATE_HOME'):
+       return 
+    
+    if not os.environ.has_key('DEPOT_HOME'):
+        raise RuntimeError, 'Please set $DEPOT_HOME (or $DEPOT_UPDATE_HOME) to where Apache
Depot is installed.'
+    
+def callDepotJavaCommand(iargs,command):
+    """
+    
+    	Ask Depot to perform that command
+    	
+    """
+    
+    if 'update' == command:
+        javaClass = 'org.apache.depot.update.tool.DownloaderTool'
+    elif 'repo' == command:
+        javaClass = 'org.apache.depot.update.tool.RepositoryTool'
+    elif 'config' == command:
+        javaClass = 'org.apache.depot.update.tool.ConfigTool'
+    
+    # Environment and CLASSPATH
+    env={}
+    cp=[]
+    
+    # Where out jar/code is...
+    depotHome=os.path.abspath(os.environ['DEPOT_UPDATE_HOME'] or os.environ['DEPOT_HOME'])
+    if verbosity.isDebug(): print "DEPOT_HOME: " + depotHome
+    depotJars=os.path.abspath(os.path.join(depotHome,'jars'))
+    depotEnv=os.path.abspath(os.path.join(depotHome,'local.env'))
+    
+    # Allow local additions
+    if os.path.exists(depotEnv):
+        if verbosity.isDebug(): print "Depot Env: " + depotEnv
+        envFile=None
+        try:
+            envFile=file(depotEnv,'r')
+    
+            # Split into a dict of NAME=VALUE (from file)
+            import re
+            envInfo=dict(re.findall('(.*?)=(.*)', envFile.read()))
+        
+            for key in envInfo.iterkeys():
+                if verbosity.isDebug(): print 'ENV : ' + key  + ' -> ' + envInfo[key]
+                env[key]=envInfo[key]             
+        finally:
+            if envFile: envFile.close()
+    else:
+        if verbosity.isDebug(): print "*No* Depot Env: " + depotEnv       
+                
+    # Original CLASSPATH
+    if env.has_key('CLASSPATH'):
+        cp=split(env['CLASSPATH'],os.pathsep)
+    elif os.environ.has_key('CLASSPATH'):
+        cp=split(os.environ['CLASSPATH'],os.pathsep)
+        
+    # Build the CLASSPATH
+    if os.path.exists(depotJars):
+        if verbosity.isDebug(): print "DEPOT JARS: " + depotJars   
+        for jar in os.listdir(depotJars):
+            if jar.endWith('.jar'):
+                if verbosity.isDebug(): print "DEPOT JAR: " + `jar`    
+                cp.append(os.path.abspath(jar))
+    else:
+        if verbosity.isDebug(): print "*No* Depot Jars: " + depotJars       
+        
+    # New CLASSPATH    
+    classpath = os.pathsep.join(cp) 
+    env['CLASSPATH'] = classpath
+    if verbosity.isDebug(): print 'Formed CLASSPATH : ' + classpath
+    
+    # Actually run the Java command
+    return runCommand(	'java ' + javaClass, 
+                        ' '.join(iargs),
+                        env)
+    
+def runCommand( command,
+                args='',
+                env=None,
+                dir=None,
+                outputFile=None):
+    """ 
+    
+        Run a command, and check the result... 
+        
+    """
+    
+    # Ensure we move to the right directory
+    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
+    verbosity=Verbosity(Verbosity.QUIET)
+    
+    try:
+        checkEnvironment()
+        
+        # The path of this command
+        depotPath = os.path.abspath(args[0])
+        del args[0]     
+        
+        if len(args) > 0:
+            command=args[0]
+            del args[0]     
+            
+            print 'Command : ' + command + ' ' + `args`
+    
+            # Call the Java command with the rest of them
+            result=callDepotJavaCommand(args,command)
+
+    except KeyboardInterrupt:    
+        if verbosity.isVerbose(): print 'Terminated by user interrupt...'
+        result = 1
+        raise
+        
+    except:    
+        if verbosity.isVerbose(): print  'Terminated unintentionally...'
+        result = 1
+        raise
+    
+    # Exiting...
+    if verbosity.isVerbose(): print  'Exited with code: ' + `result`       
+    sys.exit(result)

Added: incubator/depot/trunk/update/local.env
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/local.env	Fri Aug 13 08:28:54 2004
@@ -0,0 +1,6 @@
+CLASSPATH=.;F:\data\OSS\depot-common\build\ide\eclipse\;F:\data\OSS\depot-version\build\ide\eclipse\;F:\data\OSS\depot-update\build\ide\eclipse\;F:\data\OSS\depot-version\build\ide\eclipse\;F:\data\OSS\commons-codec\build\ide\eclipse\;F:\data\OSS\jakarta-regexp\build\ide\eclipse\;F:\data\OSS\commons-httpclient\build\ide\eclipse\;F:\data\OSS\commons-logging\build\ide\eclipse\;F:\data\OSS\jakarta-regexp\build\ide\eclipse\
+DEPOT_COMMON=F:\data\OSS\depot-common
+DEPOT_HOME=F:\data\OSS\depot-update
+DEPOT_UPDATE=F:\data\OSS\depot-update
+DEPOT_UPDATE_HOME=F:\data\OSS\depot-update
+DEPOT_VERSION=F:\data\OSS\depot-version

Added: incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/ConfigTool.java
==============================================================================
--- (empty file)
+++ incubator/depot/trunk/update/src/java/org/apache/depot/update/tool/ConfigTool.java	Fri
Aug 13 08:28:54 2004
@@ -0,0 +1,53 @@
+/*
+ * Copyright  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.
+ */
+package org.apache.depot.update.tool;
+import org.apache.depot.common.util.cli.CommandLine;
+import org.apache.depot.common.util.cli.Option;
+import org.apache.depot.update.config.UpdaterConfig;
+import org.apache.depot.update.impl.ReferenceManager;
+/**
+ */
+public class ConfigTool extends Tool {
+	private static Option l_configOption = null;
+	static {
+		l_configOption = new Option("c", "config", true,
+				"The configuration file");
+	}
+
+	protected String getTitle() {
+		return "Updater Configuration Tool";
+	}
+
+	protected void init() {
+		getOptions().addOption(l_configOption);
+	}
+
+	public void execute(CommandLine cmdline) throws Exception {
+		// Optional configuration
+		String configName = cmdline.getOptionValue(l_configOption);
+
+		if (null != configName)
+			UpdaterConfig.configure(configName);
+		else
+			UpdaterConfig.configure();
+
+		ReferenceManager.dump();
+	}
+
+	public static void main(String[] args) {
+		(new ConfigTool()).run(args);
+	}
+}
\ No newline at end of file

Mime
View raw message