[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[myserver-commit] [3015] myserver-get: first implementation of install c
From: |
Daniele Perrone |
Subject: |
[myserver-commit] [3015] myserver-get: first implementation of install command. |
Date: |
Thu, 26 Feb 2009 20:26:14 +0000 |
Revision: 3015
http://svn.sv.gnu.org/viewvc/?view=rev&root=myserver&revision=3015
Author: dperrone
Date: 2009-02-26 20:26:13 +0000 (Thu, 26 Feb 2009)
Log Message:
-----------
myserver-get: first implementation of install command.
Modified Paths:
--------------
trunk/misc/myserver-get/myserver-get.py
trunk/misc/myserver-get/myserverGetLib/config.py
trunk/misc/myserver-get/myserverGetLib/console.py
trunk/misc/myserver-get/myserverGetLib/general.py
trunk/misc/myserver-get/myserverGetLib/remote.py
trunk/misc/myserver-get/myserverGetLib/remoteGenericUrl.py
Modified: trunk/misc/myserver-get/myserver-get.py
===================================================================
--- trunk/misc/myserver-get/myserver-get.py 2009-02-25 21:03:55 UTC (rev
3014)
+++ trunk/misc/myserver-get/myserver-get.py 2009-02-26 20:26:13 UTC (rev
3015)
@@ -11,7 +11,19 @@
myserverGet = MyServerGet()
command = ""
- commands = {"":usage, "update":myserverGet.update,
"search":myserverGet.search}
+ commands = {"":usage, "update":myserverGet.update,
"search":myserverGet.search,"install":myserverGet.install}
+
+
+ import os
+ if os.name=="nt":
+ myserverGetLib.config.arch = "win32"
+ else:
+ import string
+ myserverGetLib.config.arch = string.lower(os.uname()[0])
+ if string.find(os.uname()[4],"64")==-1:
+ myserverGetLib.config.arch = myserverGetLib.config.arch + "32"
+ else:
+ myserverGetLib.config.arch = myserverGetLib.config.arch + "64"
try:
opts, args = getopt.getopt(argv, "hv", ["help","verbose"])
@@ -23,11 +35,11 @@
usage("")
sys.exit()
elif opt in ("-v", "--verbose"):
- myserverGetLib.config.VERBOSE = True
+ myserverGetLib.config.verbose = True
arguments = []
for arg in args:
- if arg in ("update","search"):
+ if arg in ("update","search","install"):
command = arg
else:
arguments.append(arg)
Modified: trunk/misc/myserver-get/myserverGetLib/config.py
===================================================================
--- trunk/misc/myserver-get/myserverGetLib/config.py 2009-02-25 21:03:55 UTC
(rev 3014)
+++ trunk/misc/myserver-get/myserverGetLib/config.py 2009-02-26 20:26:13 UTC
(rev 3015)
@@ -9,8 +9,14 @@
PLUGIN_LIST_SUFFIX = "-plugin-list.xml"
-VERBOSE = False
+MYSERVER_PLUGIN_DIR = "../../myserver/binaries/plugins"
+MYSERVER_VERSION = "0.9"
+
+verbose = False
+
+arch = ""
+
class ConfigLoader:
def __init__(self, configFile):
self.__configFile = configFile
\ No newline at end of file
Modified: trunk/misc/myserver-get/myserverGetLib/console.py
===================================================================
--- trunk/misc/myserver-get/myserverGetLib/console.py 2009-02-25 21:03:55 UTC
(rev 3014)
+++ trunk/misc/myserver-get/myserverGetLib/console.py 2009-02-26 20:26:13 UTC
(rev 3015)
@@ -5,4 +5,7 @@
sys.stdout.flush()
def writeln(arg):
- write(arg + "\n")
\ No newline at end of file
+ write(arg + "\n")
+
+def readln():
+ return sys.stdin.readline()
\ No newline at end of file
Modified: trunk/misc/myserver-get/myserverGetLib/general.py
===================================================================
--- trunk/misc/myserver-get/myserverGetLib/general.py 2009-02-25 21:03:55 UTC
(rev 3014)
+++ trunk/misc/myserver-get/myserverGetLib/general.py 2009-02-26 20:26:13 UTC
(rev 3015)
@@ -5,6 +5,8 @@
import remoteSvn
import remoteGenericUrl
import console
+import re
+import string
class MyServerGet:
def __init__(self, repositoryFile = config.REP_LIST_FILE, listDir =
config.PLUGIN_LIST_FILES_DIR):
@@ -16,7 +18,16 @@
self.__repManager.addSupportedRepository("ftp",remoteGenericUrl.RepositoryGenericUrl)
self.__list = []
self.loadRepositoryList()
+ self.__versionRegex =
re.compile(r'^([1-2]?[1-9]?[0-9])?(.[1-2]?[0-9]?[0-9])?(.[1-2]?[0-9]?[0-9])?(.[1-2]?[0-9]?[0-9])?$')
+
+ def __versionConverter(self,versionString):
+ numbers = [int(string.replace(dirtyNumber,'.','')) for dirtyNumber in
self.__versionRegex.search(versionString).groups() if dirtyNumber != None]
+ result = 0
+ for i in range(len(numbers)):
+ result = numbers[i] << 8*(4-i)
+ return result
+
def loadRepositoryList(self):
list = xml.dom.minidom.parse(self.__rep)
repXmlList = list.getElementsByTagName("REPOSITORY")
@@ -30,7 +41,6 @@
def __search(self,arg):
- import string
results = []
for list in self.__list:
plugins = list.getPluginsList()
@@ -41,10 +51,94 @@
def search(self,arg):
arg = " ".join(arg)
- if config.VERBOSE:
+ if config.verbose:
results = ["- " + plugin["name"][0]["value"] + " (compatible with
GNU MyServer version ["+plugin.getMyServerMinVersion() + "," +
plugin.getMyServerMinVersion() + "])\n " + plugin["description"][0]["value"]
+ "\n Dependences: " + " ".join(dep["value"] + "[" + dep["min-version"] +
"," + dep["max-version"] + "]" for dep in plugin["depends"]) for plugin in
self.__search(arg)]
else:
results = [plugin["name"][0]["value"] + " - " +
plugin["description"][0]["value"] for plugin in self.__search(arg)]
console.writeln("\n".join(results))
-
-
\ No newline at end of file
+
+ def __find(self,arg):
+ for list in self.__list:
+ plugins = list.getPluginsList()
+ for plugin in plugins:
+ if string.lower(plugin["name"][0]["value"]) ==
string.lower(arg):
+ return (plugin,list)
+ return [None, None]
+
+ def __recursiveDependencesChecker(self,pluginRoot):
+ result = []
+ errors = []
+ for dep in pluginRoot["depends"]:
+ (plugin, list) = self.__find(dep["value"])
+ if plugin == None:
+ errors.append((pluginRoot,"Missing dependence: %s" %
(dep["value"])))
+ continue
+ minversion = self.__versionConverter(dep["min-version"])
+ maxversion = self.__versionConverter(dep["max-version"])
+ pluginversion =
self.__versionConverter(plugin["version"][0]["value"])
+ if pluginversion < minversion or pluginversion > maxversion:
+ errors.append((pluginRoot,"%s%s is going to be installed, but
%s requires version > %s and version < %s" %
(dep["value"],plugin["version"][0]["value"],pluginRoot["version"][0]["value"],dep["min-version"],dep["max-version"])))
+ continue
+ result.append((plugin, list))
+ [res, er] = self.__recursiveDependencesChecker(plugin)
+ result.extend(res)
+ errors.extend(er)
+ return (result,errors)
+
+ def install(self,args):
+ for arg in args:
+ (plugin,list) = self.__find(arg)
+ if plugin == None:
+ console.writeln("No plugin with this name is present in the
plugin database.")
+ return None
+
+ myserverVersion = self.__versionConverter(config.MYSERVER_VERSION)
+ minversion =
self.__versionConverter(plugin.getMyServerMinVersion())
+ maxversion =
self.__versionConverter(plugin.getMyServerMaxVersion())
+ if myserverVersion < minversion or myserverVersion > maxversion:
+ console.writeln("Plugin incompatible with GNU MyServer
installed version.")
+ return None
+
+
+ toInstall = [(plugin,list)]
+ (result,errors) = self.__recursiveDependencesChecker(plugin)
+ if len(errors) != 0:
+ for (plugin,msg) in errors:
+ console.writeln("Error while install %s: %s" %
(plugin["name"][0]["value"],msg))
+ return None
+ toInstall.extend(result)
+
+ console.write ("the following plugins will be installed:\n %s\n do
you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"] for
(plugin,list) in toInstall)))
+ resp = string.lower(console.readln())
+
+ while not resp in ("y\n","n\n","\n"):
+ console.write ("the following plugins will be installed:\n
%s\n do you want to continue?[Y|n] " % (", ".join(plugin["name"][0]["value"]
for (plugin,list) in toInstall)))
+ resp = string.lower(console.readln())
+ if resp == 'n\n':
+ console.writeln ("Install aborted.")
+ return None
+
+ downloadErrors = []
+ for (plugin,list) in toInstall:
+ rep = self.__repManager.getRepository(list.repository)
+ rep = rep(list.repository)
+ if not rep.getPluginBinary(list,plugin):
+ downloadErrors.append(plugin)
+
+ if len(downloadErrors) != 0:
+ console.writeln ("Errors retriving the follow plugins
packages: %s" % (" ".join("%s-%s-%s.tar.gz" %
(plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch) for
plugin in downloadErrors)))
+ return None
+
+ for (plugin,list) in toInstall:
+ filename = config.MYSERVER_PLUGIN_DIR + "/%s-%s-%s.tar.gz" %
(plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch)
+ import tarfile
+ console.writeln("Exctracting plugin package..")
+ try:
+ tarf = tarfile.open(filename.encode("ascii"),"r|gz")
+ tarf.extractall (config.MYSERVER_PLUGIN_DIR)
+ except Exception:
+ console.writeln("Error while exctracting plugin package!")
+ return None
+ import os
+ os.remove(filename)
+ console.writeln("plugin %s installed." %
(plugin["name"][0]["value"]))
\ No newline at end of file
Modified: trunk/misc/myserver-get/myserverGetLib/remote.py
===================================================================
--- trunk/misc/myserver-get/myserverGetLib/remote.py 2009-02-25 21:03:55 UTC
(rev 3014)
+++ trunk/misc/myserver-get/myserverGetLib/remote.py 2009-02-26 20:26:13 UTC
(rev 3015)
@@ -8,8 +8,9 @@
def synchronizeListWithRepository(self, list):
pass
+ def getPluginBinary(self,list,plugin):
+ pass
-
class RepositoryManager:
def __init__(self):
self.__reps = {}
Modified: trunk/misc/myserver-get/myserverGetLib/remoteGenericUrl.py
===================================================================
--- trunk/misc/myserver-get/myserverGetLib/remoteGenericUrl.py 2009-02-25
21:03:55 UTC (rev 3014)
+++ trunk/misc/myserver-get/myserverGetLib/remoteGenericUrl.py 2009-02-26
20:26:13 UTC (rev 3015)
@@ -4,6 +4,7 @@
from remote import Repository
import console
import urllib
+import config
class RepositoryGenericUrl(Repository):
def __init__ (self,url):
@@ -45,4 +46,15 @@
pluginInfo = list.addPluginWithXml(element[0])
list.synchronizeListWithFileSystem()
console.write("DONE.\n")
-
+
+ def getPluginBinary(self,list,plugin):
+ url ="%s/pub/%s-%s-%s.tar.gz" %
(list.repository,plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch)
+ filename = config.MYSERVER_PLUGIN_DIR + "/%s-%s-%s.tar.gz" %
(plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch)
+ console.writeln("Downloading %s-%s-%s.tar.gz..." %
(plugin["name"][0]["value"],plugin["version"][0]["value"],config.arch))
+ try:
+ urllib.urlretrieve(url, filename)
+ except Exception:
+ console.writeln("Error while retriving remote file!")
+ return False
+ return True
+
\ No newline at end of file
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [myserver-commit] [3015] myserver-get: first implementation of install command.,
Daniele Perrone <=