[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.newcomer] python script for eclipse nightlies install/overwrite
|
- From: slamdunkinpool@xxxxxxxxx (slamdunkinpool)
- Date: Tue, 14 Mar 2006 05:41:08 +0000 (UTC)
- Newsgroups: eclipse.newcomer
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
Hi,
I wrote this small python script to copy plugins and features directory
tree from the downloaded eclipse dir to the installed eclipse dir. Just
edit the EclipseInstallPath and EclipseDownloadedPath variables according
to your directory locations.
#
# Author : slamdunkinpool
#
import os
import time
import shutil
import string
import re
# 1. Read file/dir names from eclipse install dir
# 2. split each file/dir name to fill in multidimension array
# sample names:
# org.eclipse.somepkg_3.2.0.N20060306-0010
# org.eclipse.somepkg2_3.2.0.N20060306
# org.eclipse.some_pkg_3.2.0.N20060306
# org.eclipse.some_pkg_3.2.0.N200603060010
#
# [org.eclipse.somepkg][_3.2.0].[N20060306]-0010
# [--------X----------][--Y---] [----Z----]
# [----------------------S----------------------]
#
# Arrays S,A,B,C
# initialize with "" value
# A[i] = B[i] = C[i] = ""
# A[i] = X
# B[i] = Y
# C[i] = Z
#
# c - current installed, n - new downloaded files
# loop:
# i=1
# if Xc == Xn then
# i =2
# if Yc < Yn then
# overwrite Sc with Sn file/dir
# else if Yc == Yn and Zc < Zn then
# overwrite Sc with Sn file/dir
# end loop
# if i < 2 then
# #new file/dir
# copy Sn file/dir to install dir
#
#
#
# ----- GLOBAL PATHS -------------
# --------------------------------------------------------------
#
# *** I M P O R T A N T ***
#
# " HARDCODED " DIRECTORY PATHS
#
# EDIT: EclipseInstallPath & EclipseDownloadPath
#
# --------------------------------------------------------------
EclipseInstallPath = "G:\\eclipse3.1M5a\\eclipse32\\eclipse"
EclipseDownloadPath =
"G:\\myDownloads\\DOWNLOADS\\eclipse-SDK-I20060309-1000-win32\\eclipse"
EPluginsPath = os.path.join(EclipseInstallPath, "plugins")
EFeaturesPath = os.path.join(EclipseInstallPath, "features")
EDPluginsPath = os.path.join(EclipseDownloadPath, "plugins")
EDFeaturesPath = os.path.join(EclipseDownloadPath, "features")
# current working dir
appPath = os.getcwd()
#------ FUNCTIONS --------
def dirList(path):
try:
if os.path.exists(path):
fnames = os.listdir(path)
return fnames
else:
print "Warning: dirList, %s, directory not found" % (`path`)
return None
except Exception, exs:
print "Error: dirList, %s: %s" % (`path`,str(exs))
def dumpFileList(f):
try:
if f is None:
print 'Info: no files in %s, exiting...' % (`f`)
_ = raw_input('press ENTER to exit...')
os.exit(0)
return;
li = []
s = x = y = z = ''
p = re.compile(r'_\d{1,5}\.\d{1,5}\.\d{1,5}')
p2 = re.compile(r'\.[a-zA-Z]\d{8}')
for fi in f:
# RE-ZERO
s = x = y = z = ''
#print fi
s = fi
# SEARCH '_3.2.0' PATTERN
m = p.search(fi)
if m:
#print m.group()[1:]
y = m.group()[1:]
#print fi[0:m.start()]
x = fi[0:m.start()]
else:
#print 'No match'
# SKIP THIS VALUE
continue
# SEARCH '.N20060310' PATTERN
m = p2.search(fi)
if m:
#print m.group()[1:]
z = m.group()[1:]
## else:
## #print 'No match'
li.append([s,x,y,z])
return li
except Exception, e:
print "Error: dumpFileList, %s: %s" % (`fi`, str(e))
_ = raw_input('press ENTER to exit...')
os._exit(0)
def deleteFile(dstname):
try:
if os.path.isdir(dstname):
shutil.rmtree(dstname)
else:
os.remove(dstname)
except Exception, exd:
print "Error, deleteFile, %s: %s" % (`dstname`,str(exd))
def copyNew(srcname, dstname):
try:
if os.path.isdir(srcname):
print srcname + ' :::: ' + dstname
try:
shutil.copytree(srcname, dstname)
except IOError, v:
print "Error, copyNew, IOError, %s -- %s :: %s" % (str(v),
`srcname`, `dstname`)
except OSError, v:
print "Error, copyNew, OSError, %s -- %s :: %s" % (str(v),
`srcname`, `dstname`)
except Exception, ex:
print "Error, copyNew, Exception, %s -- %s :: %s" %
(str(ex), `srcname`, `dstname`)
else:
print srcname + ' :: ' + dstname
shutil.copy2(srcname, dstname)
except Exception, exd:
print "Error, copyNew, %s %s: %s" % (`srcname`, `dstname`,str(exd))
def replaceTree(oldtree, newtreeSrc, newtreeDst):
try:
deleteFile(oldtree)
copyNew( newtreeSrc, newtreeDst)
except Exception, exd:
print "Error, replaceTree %s %s %s %s" %
(`oldtree`,`newtreeSrc`,`newtreeDst`,str(exd))
def compareDirs(mainDir, newDir):
try:
fList = dirList(mainDir)
oldList = dumpFileList(fList)
fNList = dirList(newDir)
newList = dumpFileList(fNList)
if len(oldList) < 1:
os._exit(0)
if len(newList) < 1:
os._exit(0)
for nli in newList:
i = 1
for oli in oldList:
if oli[1] == nli[1]:
i = 2
if oli[2] < nli[2]:
## print oli[0] + ' ' + nli[0]
replaceTree( os.path.join( mainDir, oli[0]
),os.path.join( newDir, nli[0] ),os.path.join( mainDir, nli[0] ))
elif oli[2] == nli[2] and oli[3][1:] < nli[3][1:]:
## print oli[0] + ' ' + nli[0]
replaceTree( os.path.join( mainDir, oli[0]
),os.path.join( newDir, nli[0] ),os.path.join( mainDir, nli[0] ))
time.sleep(0.1)
break
if i < 2:
copyNew( os.path.join( newDir, nli[0] ), os.path.join(
mainDir, nli[0] ))
except Exception, e:
print "Error: compareDir, %s" % (str(e))
def copyFilesOnly(srcname, dstname):
try:
flist = os.listdir( srcname )
for f in flist:
if os.path.isdir(os.path.join(srcname,f)):
print 'skip dir :: ' + f
else:
print os.path.join(srcname,f) + ' :: ' +
os.path.join(dstname, f)
shutil.copy2(os.path.join(srcname,f),
os.path.join(dstname, f))
except Exception, exd:
print "Error, copyNew, %s: %s" % (`dstname`,str(exd))
#------- END FUNCTIONS ----
#-------- MAIN CODE EXECUTION---------------------
copyFilesOnly (EclipseDownloadPath, EclipseInstallPath)
compareDirs(EPluginsPath, EDPluginsPath)
compareDirs(EFeaturesPath, EDFeaturesPath)
# AT END OF EXECUTION PROMPT USER TO PRESS ENTER KEY
# THIS WILL KEEP SHELL WINDOW OPEN SO THAT USER CAN
# SEE IF ANY ERROR OCCURED ETC.
print "------------------------------------------"
print " END ... press ENTER to stop script..."
print "------------------------------------------"
_ = raw_input('press ENTER key ...')
#os._exit(0)