Beispiel #1
0
    def add_command(self, type, folder, data, dirty, env_data):
        if not data:
            blob = None
        else:
            blob = util.BlobType(util.CompatPickle(data))
        if not folder:
            folder_id = None
        else:
            folder_id = folder.id

        env_id = None
        tools_env = None
        if env_data is not None:
            tools_env = self.add_environment(env_data)
            env_id = tools_env.env_id

        query = "insert into nodes (type, folder, data, dirty, env_id) values (?, ?, ?, ?, ?)"
        cursor = self.cn.execute(query, (type, folder_id, blob, dirty, env_id))

        entry = Entry(id=cursor.lastrowid,
                      type=type,
                      path=None,
                      blob=data,
                      folder=folder,
                      stamp=0,
                      dirty=nodetypes.DIRTY)
        entry.tools_env = tools_env

        self.node_cache_[entry.id] = entry
        return entry
Beispiel #2
0
    def add_environment(self, env_data):
        if env_data in self.env_reverse_lookup_:
            return self.env_reverse_lookup_[env_data]

        stamp = time.time()
        blob = util.BlobType(util.CompatPickle(env_data))
        query = "INSERT INTO environments (stamp, data) VALUES (?, ?)"
        cursor = self.cn.execute(query, (stamp, blob))

        tools_env = nodetypes.ToolsEnv(cursor.lastrowid, env_data)
        self.env_cache_[tools_env.env_id] = tools_env
        self.env_reverse_lookup_[env_data] = tools_env
        return tools_env
Beispiel #3
0
    def update_command(self, entry, type, folder, data, dirty, refactoring):
        if not data:
            blob = None
        else:
            blob = util.BlobType(util.CompatPickle(data))

        if entry.type == type and \
           entry.folder == folder and \
           entry.blob == data and \
           (dirty == nodetypes.ALWAYS_DIRTY) == (entry.dirty == nodetypes.ALWAYS_DIRTY):
            return False

        if refactoring:
            util.con_err(util.ConsoleRed, 'Command changed! \n',
                         util.ConsoleRed, 'Old: ', util.ConsoleBlue,
                         entry.format(), util.ConsoleNormal)
            entry.type = type
            entry.folder = folder
            entry.blob = data
            util.con_err(util.ConsoleRed, 'New: ', util.ConsoleBlue,
                         entry.format(), util.ConsoleNormal)
            raise Exception('Refactoring error: command changed')

        if not folder:
            folder_id = None
        else:
            folder_id = folder.id

        query = """
      update nodes
      set
        type = ?,
        folder = ?,
        data = ?,
        dirty = ?
      where id = ?
    """
        self.cn.execute(query, (type, folder_id, blob, dirty, entry.id))
        entry.type = type
        entry.folder = folder
        entry.blob = blob
        entry.dirty = dirty
        return True
Beispiel #4
0
    def add_command(self, type, folder, data):
        if not data:
            blob = None
        else:
            blob = util.BlobType(util.CompatPickle(data))
        if not folder:
            folder_id = None
        else:
            folder_id = folder.id

        query = "insert into nodes (type, folder, data, dirty) values (?, ?, ?, ?)"
        cursor = self.cn.execute(query, (type, folder_id, blob, 1))

        entry = Entry(id=cursor.lastrowid,
                      type=type,
                      path=None,
                      blob=data,
                      folder=folder,
                      stamp=0,
                      dirty=True)
        self.node_cache_[entry.id] = entry
        return entry
Beispiel #5
0
    def update_command(self, entry, type, folder, data, dirty, refactoring,
                       env_data):
        if not data:
            blob = None
        else:
            blob = util.BlobType(util.CompatPickle(data))

        # Note: it's a little gross/inconsistent how updates are handled. It seems
        # like Database should not be detecting refactoring, and then, we would not
        # need to pass env_id (which is stored in Entry for only this purpose).
        only_env_differs = False
        if entry.type == type and \
           entry.folder == folder and \
           entry.blob == data and \
           (dirty == nodetypes.ALWAYS_DIRTY) == (entry.dirty == nodetypes.ALWAYS_DIRTY):
            if nodetypes.IsSameEnvData(entry.tools_env, env_data):
                return False
            only_env_differs = True

        # Always mark changed nodes as dirty.
        if dirty != nodetypes.ALWAYS_DIRTY:
            dirty = nodetypes.DIRTY

        entry.type = type
        entry.folder = folder
        entry.blob = data
        entry.dirty = dirty

        env_id = None
        if env_data is not None:
            entry.tools_env = self.add_environment(env_data)
            env_id = entry.tools_env.env_id

        if refactoring:
            if only_env_differs:
                util.con_err(util.ConsoleRed, 'Command environment changed!\n',
                             util.ConsoleBlue, entry.format(),
                             util.ConsoleNormal)
            else:
                util.con_err(util.ConsoleRed, 'Command changed!\n',
                             util.ConsoleRed, 'Old: ', util.ConsoleBlue,
                             entry.format(), util.ConsoleNormal)
                util.con_err(util.ConsoleRed, 'New: ', util.ConsoleBlue,
                             entry.format(), util.ConsoleNormal)
            raise Exception('Refactoring error: command changed')

        if not folder:
            folder_id = None
        else:
            folder_id = folder.id

        query = """
      update nodes
      set
        type = ?,
        folder = ?,
        data = ?,
        dirty = ?,
        env_id = ?
      where id = ?
    """
        self.cn.execute(query,
                        (type, folder_id, blob, dirty, env_id, entry.id))
        return True