installer.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 #based on script for SCALA see https://github.com/scala-ide/scala-ide
00004 #ported to python an adapted for BRIDE
00005 
00006 import roslib
00007 import os
00008 import sys
00009 import subprocess
00010 import yaml
00011 import yaml.constructor
00012 try:
00013         from collections import OrderedDict
00014 except ImportError:
00015         print "Python 2.7+ OrderedDict collection not available"
00016         try:
00017                 from ordereddict import OrderedDict
00018                 print "Using backported OrderedDict implementation"
00019         except ImportError:
00020                 print "Backported OrderedDict implementation not available"
00021 
00022 class OrderedDictYAMLLoader(yaml.Loader):
00023     """
00024     A YAML loader that loads mappings into ordered dictionaries. Taken from gist https://gist.github.com/enaeseth/844388
00025     """
00026  
00027     def __init__(self, *args, **kwargs):
00028         yaml.Loader.__init__(self, *args, **kwargs)
00029  
00030         self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
00031         self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)
00032  
00033     def construct_yaml_map(self, node):
00034         data = OrderedDict()
00035         yield data
00036         value = self.construct_mapping(node)
00037         data.update(value)
00038  
00039     def construct_mapping(self, node, deep=False):
00040         if isinstance(node, yaml.MappingNode):
00041             self.flatten_mapping(node)
00042         else:
00043             raise yaml.constructor.ConstructorError(None, None,
00044                 'expected a mapping node, but found %s' % node.id, node.start_mark)
00045  
00046         mapping = OrderedDict()
00047         for key_node, value_node in node.value:
00048             key = self.construct_object(key_node, deep=deep)
00049             try:
00050                 hash(key)
00051             except TypeError, exc:
00052                 raise yaml.constructor.ConstructorError('while constructing a mapping',
00053                     node.start_mark, 'found unacceptable key (%s)' % exc, key_node.start_mark)
00054             value = self.construct_object(value_node, deep=deep)
00055             mapping[key] = value
00056         return mapping
00057 
00058 
00059 eclipse_app = "org.eclipse.equinox.p2.director"
00060 eclipse_opts = "-nosplash"
00061 
00062 def install(eclipse_repo, eclipse_component):
00063         p = subprocess.Popen("./eclipse/eclipse " + eclipse_opts + " -application " + eclipse_app + " -repository " + eclipse_repo + " -installIU " + eclipse_component, shell=True)
00064         sts = os.waitpid(p.pid, 0)[1]
00065 
00066 def uninstall(eclipse_repo, eclipse_component):
00067         p = subprocess.Popen("./eclipse/eclipse " + eclipse_opts + " -application " + eclipse_app + " -repository " + eclipse_repo + " -uninstallIU " + eclipse_component, shell=True)
00068         sts = os.waitpid(p.pid, 0)[1]
00069 
00070 def update(eclipse_repo, eclipse_component):
00071         p = subprocess.Popen("./eclipse/eclipse " + eclipse_opts + " -application " + eclipse_app + " -repository " + eclipse_repo + " -installIU " + eclipse_component + " -uninstallIU " + eclipse_component, shell=True)
00072         sts = os.waitpid(p.pid, 0)[1]
00073 
00074 
00075 def install_emfatic():
00076         eclipse_repo = "http://download.eclipse.org/emfatic/update/"
00077         eclipse_repo = "http://download.eclipse.org/epsilon/updates/"
00078         eclipse_component = "org.eclipse.emf.emfatic"
00079         eclipse_component = "org.eclipse.epsilon.feature.feature"
00080         install(eclipse_repo, eclipse_component)
00081 
00082 if __name__ == "__main__":
00083         if(len(sys.argv) == 2):
00084                 stream = file(sys.argv[1], 'r') 
00085                 toinstall = yaml.load(stream, OrderedDictYAMLLoader)
00086                 for repo in toinstall:
00087                         for package in toinstall[repo]:
00088                                 install(repo, package)
00089         elif(len(sys.argv) == 3):
00090                 if(sys.argv[1] == '-u'):
00091                         stream = file(sys.argv[2], 'r') 
00092                         toinstall = yaml.load(stream)
00093                         for repo in toinstall:
00094                                 for package in toinstall[repo]:
00095                                         update(repo, package)
00096                 else:
00097                         print "Usage: installer.py [-u] resource_yaml_file"
00098         else:
00099                 print "Usage: installer.py [-u] resource_yaml_file"
00100                 


bride
Author(s): Alexander Bubeck
autogenerated on Sun Oct 5 2014 22:38:22