Beispiel #1
0
 def delete(self, gist, fs_remove=True):
     gist = Gist.guess_instance(gist)
     try:
         Session().delete(gist)
         if fs_remove:
             self.__delete_gist(gist)
         else:
             log.debug('skipping removal from filesystem')
     except Exception:
         log.error(traceback.format_exc())
         raise
Beispiel #2
0
 def delete(self, gist, fs_remove=True):
     gist = Gist.guess_instance(gist)
     try:
         Session().delete(gist)
         if fs_remove:
             self.__delete_gist(gist)
         else:
             log.debug('skipping removal from filesystem')
     except Exception:
         log.error(traceback.format_exc())
         raise
Beispiel #3
0
    def update(self, gist, description, owner, ip_addr, gist_mapping,
               gist_type, lifetime):
        gist = Gist.guess_instance(gist)
        gist_repo = gist.scm_instance

        lifetime = safe_int(lifetime, -1)
        if lifetime == 0:  # preserve old value
            gist_expires = gist.gist_expires
        else:
            gist_expires = time.time() + (lifetime *
                                          60) if lifetime != -1 else -1

        # calculate operation type based on given data
        gist_mapping_op = {}
        for k, v in gist_mapping.items():
            # add, mod, del
            if not v['org_filename'] and v['filename']:
                op = 'add'
            elif v['org_filename'] and not v['filename']:
                op = 'del'
            else:
                op = 'mod'

            v['op'] = op
            gist_mapping_op[k] = v

        gist.gist_description = description
        gist.gist_expires = gist_expires
        gist.owner = owner
        gist.gist_type = gist_type

        message = 'updated file'
        message += 's: ' if len(gist_mapping) > 1 else ': '
        message += ', '.join([x for x in gist_mapping])

        # fake Kallithea Repository object
        fake_repo = AttributeDict(
            dict(
                repo_name=os.path.join(GIST_STORE_LOC, gist.gist_access_id),
                scm_instance_no_cache=lambda: gist_repo,
            ))

        self._store_metadata(gist_repo, gist.gist_id, gist.gist_access_id,
                             owner.user_id, gist.gist_type, gist.gist_expires)

        ScmModel().update_nodes(user=owner.user_id,
                                ip_addr=ip_addr,
                                repo=fake_repo,
                                message=message,
                                nodes=gist_mapping_op,
                                trigger_push_hook=False)

        return gist
Beispiel #4
0
    def update(self, gist, description, owner, gist_mapping, gist_type,
               lifetime):
        gist = Gist.guess_instance(gist)
        gist_repo = gist.scm_instance

        lifetime = safe_int(lifetime, -1)
        if lifetime == 0:  # preserve old value
            gist_expires = gist.gist_expires
        else:
            gist_expires = time.time() + (lifetime * 60) if lifetime != -1 else -1

        #calculate operation type based on given data
        gist_mapping_op = {}
        for k, v in gist_mapping.items():
            # add, mod, del
            if not v['org_filename'] and v['filename']:
                op = 'add'
            elif v['org_filename'] and not v['filename']:
                op = 'del'
            else:
                op = 'mod'

            v['op'] = op
            gist_mapping_op[k] = v

        gist.gist_description = description
        gist.gist_expires = gist_expires
        gist.owner = owner
        gist.gist_type = gist_type

        message = 'updated file'
        message += 's: ' if len(gist_mapping) > 1 else ': '
        message += ', '.join([x for x in gist_mapping])

        #fake Kallithea Repository object
        fake_repo = AttributeDict(dict(
            repo_name=gist_repo.path,
            scm_instance_no_cache=lambda: gist_repo,
        ))

        self._store_metadata(gist_repo, gist.gist_id, gist.gist_access_id,
                             owner.user_id, gist.gist_type, gist.gist_expires)

        ScmModel().update_nodes(
            user=owner.user_id,
            repo=fake_repo,
            message=message,
            nodes=gist_mapping_op,
            trigger_push_hook=False
        )

        return gist
Beispiel #5
0
 def get_gist(self, gist):
     return Gist.guess_instance(gist)
Beispiel #6
0
 def get_gist(self, gist):
     return Gist.guess_instance(gist)