Exemple #1
0
 def __init__(self, parent=None):
     QtGui.QListWidget.__init__(self,parent)
     self.__list = ExtConnectionList.getInstance(default_connections_file())
     self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
     self.setIconSize(QtCore.QSize(32,32))
     self.loadConnections()
     self.editAct = QtGui.QAction("Edit", self)
     self.editAct.setStatusTip("Edit the selected connection")
     self.connect(self.editAct,
                  QtCore.SIGNAL("triggered()"),
                  self.editConnection)
Exemple #2
0
class DBLocator(_DBLocator, CoreLocator):

    __list = ExtConnectionList.getInstance(default_connections_file())

    class getKeyChain(object):
        def set_key(self, key, passwd):
            get_vistrails_application().keyChain.set_key(key, passwd)

        def get_key(self, key):
            return get_vistrails_application().keyChain.get_key(key)

    keyChain = getKeyChain()

    def __init__(self,
                 host,
                 port,
                 database,
                 user,
                 passwd,
                 name=None,
                 **kwargs):

        _DBLocator.__init__(self, host, port, database, user, passwd, name,
                            **kwargs)
        self.ext_connection_id = -1

    def load(self, klass=None):
        from core.vistrail.vistrail import Vistrail
        if klass is None:
            klass = Vistrail
        save_bundle = _DBLocator.load(
            self, klass.vtType,
            ThumbnailCache.getInstance().get_directory())
        if klass.vtType == DBWorkflow.vtType:
            wf = save_bundle
            klass = self.get_convert_klass(wf.vtType)
            klass.convert(wf)
            wf.locator = self
            return wf
        for obj in save_bundle.get_db_objs():
            klass = self.get_convert_klass(obj.vtType)
            klass.convert(obj)
            obj.locator = self
        return save_bundle

    def save(self, save_bundle):
        save_bundle = _DBLocator.save(self, save_bundle, False)
        for obj in save_bundle.get_db_objs():
            klass = self.get_convert_klass(obj.vtType)
            klass.convert(obj)
            obj.locator = self
        return save_bundle

    def save_as(self, save_bundle, version=None):
        save_bundle = _DBLocator.save(self, save_bundle, True, version)
        for obj in save_bundle.get_db_objs():
            klass = self.get_convert_klass(obj.vtType)
            klass.convert(obj)
            obj.locator = self
        # Need to copy images into thumbnail cache directory so references
        # won't become invalid if they are in a temp dir that gets destroyed
        # when the previous locator is closed
        import shutil
        thumb_cache = ThumbnailCache.getInstance()
        thumb_cache_dir = thumb_cache.get_directory()
        new_thumbnails = []
        for thumbnail in save_bundle.thumbnails:
            if os.path.dirname(thumbnail) == thumb_cache_dir:
                new_thumbnails.append(thumbnail)
            else:
                cachedir_thumbnail = os.path.join(thumb_cache_dir,
                                                  os.path.basename(thumbnail))
                try:
                    shutil.copyfile(thumbnail, cachedir_thumbnail)
                    new_thumbnails.append(cachedir_thumbnail)
                except Exception, e:
                    debug.critical('copying %s -> %s failed: %s' % \
                                       (thumbnail, cachedir_thumbnail, str(e)))
        save_bundle.thumbnails = new_thumbnails
        # Need to update thumbnail cache in case some references have changed
        thumb_cache.add_entries_from_files(save_bundle.thumbnails)
        return save_bundle