Пример #1
0
    def check_and_set_remotes(self):
        if get_default_mucua() == self.mucua:
            r_mucua = self.mucuia
        else:
            r_mucua = self.mucua

        remotes = discover()
        logger.debug("Mucuas" + str(remotes))
        access_URI = remotes.get(r_mucua.description, "")

        if access_URI != "":
            remote = access_URI
        elif r_mucua.uri_backend != "":
            remote = r_mucua.uri_backend
        else:
            remote = ""

        logger.debug("Remote" + str(remotes))

        try:
            repository = get_default_repository()
        except DatabaseError:
            pass

        git_remote_remove(r_mucua.description, repository.get_path())
        if remote != "" and self.is_active:
            logger.debug("Adicionando " + str(remote) + " em " +
                         str(repository.get_path()))
            git_remote_add(r_mucua.description, remote, repository.get_path())
Пример #2
0
    def check_and_set_remotes(self):
        if get_default_mucua() == self.mucua:
            r_mucua = self.mucuia
        else:
            r_mucua = self.mucua
            
        remotes = discover()
        logger.debug("Mucuas" + str(remotes))
        access_URI = remotes.get(r_mucua.description, "")
        
        if access_URI != "":
            remote = access_URI
        elif r_mucua.uri_backend != "":
            remote = r_mucua.uri_backend
        else:
            remote = ""
        
        logger.debug("Remote" + str(remotes))

        try:
            repository = get_default_repository()
        except DatabaseError:
            pass

        git_remote_remove(r_mucua.description, repository.get_path())
        if remote != "" and self.is_active: 
            logger.debug("Adicionando " + str(remote) + " em " + str(repository.get_path()))
            git_remote_add(r_mucua.description, remote, repository.get_path())
Пример #3
0
    def del_territory(self, territory, repository):
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        git_annex_group_del(repository.get_path(), self.get_description(),
                            territory)
Пример #4
0
def get_mucua_info(uuid, repository=None):
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    status = git_annex_status(repository.get_path())

    return status
Пример #5
0
def get_mucua_info(uuid, repository=None):
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    status = git_annex_status(repository.get_path())
    
    return status
Пример #6
0
    def add_group(self, group, repository):
        u"""Retorna a lista de grupos da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        git_annex_group_add(repository.get_path(), self.get_description(),
                            group)
Пример #7
0
    def del_territory(self, territory, repository):
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        git_annex_group_del(repository.get_path(),
                            self.get_description(),
                            territory)
Пример #8
0
    def add_group(self, group, repository):
        u"""Retorna a lista de grupos da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        git_annex_group_add(repository.get_path(),
                            self.get_description(),
                            group)
Пример #9
0
    def get_groups(self, repository):
        u"""Retorna a lista de grupos da mucua"""

        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []
        

        return [group for group in git_annex_group_list(repository.get_path(),
                                                        self.uuid) 
                if not group.startswith('t:')]
Пример #10
0
    def get_groups(self, repository):
        u"""Retorna a lista de grupos da mucua"""

        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        return [
            group
            for group in git_annex_group_list(repository.get_path(), self.uuid)
            if not group.startswith('t:')
        ]
Пример #11
0
def create_objects_from_files(repository=get_default_repository().name):
    """Recria os midias no Django a partir dos medias serializados em JSON."""
    try:
        repository = Repository.objects.get(
            name=repository)
    except Repository.DoesNotExist:
        return None

    logger.info(u">>> %s" % _('DESERIALIZING'))
    logger.info(u"%s: %s" % (_('Repository'),  repository))
    logger.debug(u"%s \n %s" % (_('List of media found in repository..'), get_latest_media(repository).splitlines()))
    try:
        for serialized_media in get_latest_media(repository).splitlines():
            logger.info(u"%s: %s" % (_('Serialized Media'), serialized_media))
            media_json_file_path = os.path.join(REPOSITORY_DIR,
                                                repository.name,
                                                serialized_media)
            media_json_file = open(media_json_file_path)
            data = JSONParser().parse(media_json_file)
            
            try:
                media = Media.objects.get(uuid=data["uuid"])
                serializer = MediaSerializer(media, data=data, partial=True)
                print serializer.is_valid()
                print serializer.errors
                serializer.object.save()            
                logger.info(u"%s" % _('This media already exist. Updated.'))
                
            except Media.DoesNotExist:
                #dumpclean(data)
                serializer = MediaSerializer(data=data)
                print serializer.is_valid()
                print serializer.errors
                serializer.object.save()
                logger.info(u"%s" % _('New media created'))
            

            # Atualiza o arquivo lastSyncMark
            path = os.path.join(REPOSITORY_DIR, repository.name)
            output = subprocess.check_output(
                ["git", "log", "--pretty=format:'%H'", "-n 1"],
                cwd=path)
            logger.debug(u"%s: %s" % (_('Revision is'), output))
            logger.info('<<<')
            last_sync_mark = open(os.path.join(path, 'lastSync.txt'), 'w+')
            last_sync_mark.write(output)
            last_sync_mark.close()

    except CommandError:
        pass
Пример #12
0
    def get_territory(self, repository):
        u"""Retorna o territorio da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        groups = git_annex_group_list(repository.get_path(), self.uuid)
        territory = ''
        for group in groups:
            if group.startswith('t:'):
                territory = group

        return territory[2:]
Пример #13
0
def create_objects_from_files(repository=get_default_repository().name):
    """Recria os midias no Django a partir dos medias serializados em JSON."""
    try:
        repository = Repository.objects.get(name=repository)
    except Repository.DoesNotExist:
        return None

    logger.info(u">>> %s" % _('DESERIALIZING'))
    logger.info(u"%s: %s" % (_('Repository'), repository))
    logger.debug(u"%s \n %s" % (_('List of media found in repository..'),
                                get_latest_media(repository).splitlines()))
    try:
        for serialized_media in get_latest_media(repository).splitlines():
            logger.info(u"%s: %s" % (_('Serialized Media'), serialized_media))
            media_json_file_path = os.path.join(REPOSITORY_DIR,
                                                repository.name,
                                                serialized_media)
            media_json_file = open(media_json_file_path)
            data = JSONParser().parse(media_json_file)

            try:
                media = Media.objects.get(uuid=data["uuid"])
                serializer = MediaSerializer(media, data=data, partial=True)
                print serializer.is_valid()
                print serializer.errors
                serializer.object.save()
                logger.info(u"%s" % _('This media already exist. Updated.'))

            except Media.DoesNotExist:
                #dumpclean(data)
                serializer = MediaSerializer(data=data)
                print serializer.is_valid()
                print serializer.errors
                serializer.object.save()
                logger.info(u"%s" % _('New media created'))

            # Atualiza o arquivo lastSyncMark
            path = os.path.join(REPOSITORY_DIR, repository.name)
            output = subprocess.check_output(
                ["git", "log", "--pretty=format:'%H'", "-n 1"], cwd=path)
            logger.debug(u"%s: %s" % (_('Revision is'), output))
            logger.info('<<<')
            last_sync_mark = open(os.path.join(path, 'lastSync.txt'), 'w+')
            last_sync_mark.write(output)
            last_sync_mark.close()

    except CommandError:
        pass
Пример #14
0
def get_available_mucuas(uuid=None, repository=None):
    u"""
    Retorna uma lista de mucuas

    A lista são tuplas com uuid e descrição, por ex.:
    [('41f7a561-9678-437e-8f74-9531e67f2aea','dpadua'), 
    ('72c5d0e9-2bfb-43fb-bf3e-0002602b1844', 'kalakuta-laptop')]

    Atributos:
        uuid: retorna o nome (description) da mucua com 'uuid' 
        repository: retorna a lista de mucuas de 'repository'
    """
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    json_repository_status = json.loads(git_annex_status(
        repository.get_path()))

    #    logger.debug(_(u"JSON Repository status: %s") % json_repository_status)

    mucuas = []

    if uuid:
        for mucua in json_repository_status['semitrusted repositories']:
            if mucua['uuid'] == uuid:
                mucuas.append(mucua['description'].split(' ')[0])
        for mucua in json_repository_status['trusted repositories']:
            if mucua['uuid'] == uuid:
                mucuas.append(mucua['description'].split(' ')[0])

    else:
        mucuas.extend([
            (mucua['uuid'], mucua['description'].split(' ')[0])
            for mucua in json_repository_status['semitrusted repositories']
        ])
        mucuas.extend([
            (mucua['uuid'], mucua['description'].split(' ')[0])
            for mucua in json_repository_status['trusted repositories']
        ])

    mucuas = [(m[0], rpr(m[1].replace('[', '').replace(']', '')))
              for m in mucuas]
    mucuas = sorted(mucuas, key=lambda x: x[1])
    #    logger.debug(u'Mucuas: %s' % mucuas)
    return mucuas
Пример #15
0
    def get_territory(self, repository):
        u"""Retorna o territorio da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        groups = git_annex_group_list(repository.get_path(),
                                      self.uuid)
        territory = ''
        for group in groups:
            if group.startswith('t:'):
                territory = group

        return territory[2:]
Пример #16
0
def get_available_mucuas(uuid=None, repository=None):
    u"""
    Retorna uma lista de mucuas

    A lista são tuplas com uuid e descrição, por ex.:
    [('41f7a561-9678-437e-8f74-9531e67f2aea','dpadua'), 
    ('72c5d0e9-2bfb-43fb-bf3e-0002602b1844', 'kalakuta-laptop')]

    Atributos:
        uuid: retorna o nome (description) da mucua com 'uuid' 
        repository: retorna a lista de mucuas de 'repository'
    """
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    json_repository_status = json.loads(
        git_annex_status(repository.get_path()))

#    logger.debug(_(u"JSON Repository status: %s") % json_repository_status)

    mucuas = []

    if uuid:
        for mucua in json_repository_status['semitrusted repositories']:
            if mucua['uuid'] == uuid:
                mucuas.append(mucua['description'].split(' ')[0])
        for mucua in json_repository_status['trusted repositories']:
            if mucua['uuid'] == uuid:
                mucuas.append(mucua['description'].split(' ')[0])
                
    else:
        mucuas.extend([(mucua['uuid'], mucua['description'].split(' ')[0])
                       for mucua 
                       in json_repository_status['semitrusted repositories']])
        mucuas.extend([(mucua['uuid'], mucua['description'].split(' ')[0])
                       for mucua 
                       in json_repository_status['trusted repositories']])

    mucuas =  [(m[0], rpr(m[1].replace('[','').replace(']',''))) for m in mucuas]
    mucuas = sorted(mucuas, key=lambda x: x[1])
#    logger.debug(u'Mucuas: %s' % mucuas)
    return mucuas
Пример #17
0
    def set_territory(self, territory, repository):
        u"""Define o territorio da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        actual_territory = self.get_territory(repository)
        if actual_territory != '':
            if territory.startswith('t:'):
                git_annex_group_add(repository.get_path(),
                                    self.get_description(),
                                    territory)
                return _("Mucua enraizada em " + territory)
            else:
                logger.debug('Not a territory.. should start with t:')
                return _("O territorio precisa ser indicado como 't:Nome_do_territorio'")
        else: 
            return _("A mucua esta já enraizada em " + actual_territory)
Пример #18
0
    def set_territory(self, territory, repository):
        u"""Define o territorio da mucua"""
        if not repository:
            try:
                repository = get_default_repository()
            except DatabaseError:
                return []

        actual_territory = self.get_territory(repository)
        if actual_territory != '':
            if territory.startswith('t:'):
                git_annex_group_add(repository.get_path(),
                                    self.get_description(), territory)
                return _("Mucua enraizada em " + territory)
            else:
                logger.debug('Not a territory.. should start with t:')
                return _(
                    "O territorio precisa ser indicado como 't:Nome_do_territorio'"
                )
        else:
            return _("A mucua esta já enraizada em " + actual_territory)
Пример #19
0
def get_mucua_from_UUID(uuid=None, repository=None):
    """Retorna a descrição da mucua"""
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    json_repository_status = json.loads(git_annex_status(
        repository.get_path()))

    try:
        description = ''
        for mucua in json_repository_status['semitrusted repositories']:
            if mucua['uuid'] == uuid:
                description = mucua['description']

        for mucua in json_repository_status['trusted repositories']:
            if mucua['uuid'] == uuid:
                description = mucua['description']
        return rpr(description.split(' ')[0])
    except Mucua.DoesNotExists:
        return "Invalid"
Пример #20
0
def get_mucua_from_UUID(uuid=None, repository=None):
    """Retorna a descrição da mucua"""
    if not repository:
        try:
            repository = get_default_repository()
        except DatabaseError:
            return []

    json_repository_status = json.loads(
        git_annex_status(repository.get_path()))

    try:
        description = ''
        for mucua in json_repository_status['semitrusted repositories']:
            if mucua['uuid'] == uuid:
                description = mucua['description']
                
        for mucua in json_repository_status['trusted repositories']:
            if mucua['uuid'] == uuid:
                description = mucua['description']
        return rpr(description.split(' ')[0])
    except Mucua.DoesNotExists:
        return "Invalid"
def repository_get_default(request):
    repositories_list = []
    repositories_list.append(get_default_repository())
    serializer = RepositorySerializer(repositories_list, many=True)

    return Response(serializer.data)
Пример #22
0
def repository_get_default(request):
    repositories_list = []
    repositories_list.append(get_default_repository())
    serializer = RepositorySerializer(repositories_list, many=True)

    return Response(serializer.data)
Пример #23
0
def create_objects_from_files(repository=get_default_repository().name):
    """Recria os midias no Django a partir dos medias serializados em JSON."""
    try:
        repository = Repository.objects.get(
            name=repository)
    except Repository.DoesNotExist:
        return None

    logger.info(u">>> %s" % _('DESERIALIZING'))
    logger.info(u"%s: %s" % (_('Repository'),  repository))
    #logger.debug(u"%s \n %s" % (_('List of media found in repository..'), get_latest_media(repository)))
    try:
        for serialized_media in get_latest_media(repository):
            logger.info(u"%s: %s" % (_('Serialized Media'), serialized_media))
            media_json_file_path = os.path.join(REPOSITORY_DIR,
                                                repository.name,
                                                serialized_media)
            if os.path.isfile(media_json_file_path):
                with  open(media_json_file_path) as media_json_file:
		    try:
                        data = JSONParser().parse(media_json_file)
                    except:
                        print u"Problem parsing JSON: " + media_json_file.read()
                        continue

                try:
                    media = Media.objects.get(uuid=data["uuid"])
                    serializer = MediaSerializer(media, data=data, partial=True)
                    print serializer.is_valid()
                    print serializer.errors
                    serializer.object.save(is_syncing=True)
                    logger.info(u"%s" % _('This media already exist. Updated.'))
                except Media.DoesNotExist:
                    serializer = MediaSerializer(data=data)
                    print serializer.is_valid()
                    print serializer.errors
                    serializer.object.save(is_syncing=True)
                    media = serializer.object
                    logger.info(u"%s" % _('New media created'))

                # Synchronize/update tags.  
                #
                # 1) Add all tags found in the git-annex metadata and not
                # already present on the media.
                # 2) If tags from other mucuas have been deleted (are missing in
                # the git_annex metadata tags), remove them from this media.
                tags_on_media = set(git_annex_list_tags(media))
                existing_tags = set((t.namespace, t.name) for t in media.tags.all())
                # Add new tags to media
                for t in tags_on_media - existing_tags:
                    # Add tag - search for existing, if none found create new tag.
                    namespace, name = t
                    try: 
                        tag = Tag.objects.get(name=unicode(name),
                                              namespace=unicode(namespace))
                    except Tag.DoesNotExist:
                        tag = Tag(name=name, namespace=namespace)
                        tag.save()
                    media.tags.add(tag)

                # Remove tags that were removed on remote media
                for t in existing_tags - tags_on_media:
                    namespace, name = t 
                    tag = Tag.objects.get(name=name, namespace=namespace)
                    media.tags.remove(tag) 
             

    except CommandError:
        pass
Пример #24
0
def create_objects_from_files(repository=get_default_repository().name):
    """Recria os midias no Django a partir dos medias serializados em JSON."""
    try:
        repository = Repository.objects.get(name=repository)
    except Repository.DoesNotExist:
        return None

    logger.info(u">>> %s" % _('DESERIALIZING'))
    logger.info(u"%s: %s" % (_('Repository'), repository))
    #logger.debug(u"%s \n %s" % (_('List of media found in repository..'), get_latest_media(repository)))
    try:
        for serialized_media in get_latest_media(repository):
            logger.info(u"%s: %s" % (_('Serialized Media'), serialized_media))
            media_json_file_path = os.path.join(REPOSITORY_DIR,
                                                repository.name,
                                                serialized_media)
            if os.path.isfile(media_json_file_path):
                with open(media_json_file_path) as media_json_file:
                    try:
                        data = JSONParser().parse(media_json_file)
                    except:
                        print u"Problem parsing JSON: " + media_json_file.read(
                        )
                        continue

                try:
                    media = Media.objects.get(uuid=data["uuid"])
                    serializer = MediaSerializer(media,
                                                 data=data,
                                                 partial=True)
                    print serializer.is_valid()
                    print serializer.errors
                    serializer.object.save(is_syncing=True)
                    logger.info(u"%s" %
                                _('This media already exist. Updated.'))
                except Media.DoesNotExist:
                    serializer = MediaSerializer(data=data)
                    print serializer.is_valid()
                    print serializer.errors
                    serializer.object.save(is_syncing=True)
                    media = serializer.object
                    logger.info(u"%s" % _('New media created'))

                # Synchronize/update tags.
                #
                # 1) Add all tags found in the git-annex metadata and not
                # already present on the media.
                # 2) If tags from other mucuas have been deleted (are missing in
                # the git_annex metadata tags), remove them from this media.
                tags_on_media = set(git_annex_list_tags(media))
                existing_tags = set(
                    (t.namespace, t.name) for t in media.tags.all())
                # Add new tags to media
                for t in tags_on_media - existing_tags:
                    # Add tag - search for existing, if none found create new tag.
                    namespace, name = t
                    try:
                        tag = Tag.objects.get(name=unicode(name),
                                              namespace=unicode(namespace))
                    except Tag.DoesNotExist:
                        tag = Tag(name=name, namespace=namespace)
                        tag.save()
                    media.tags.add(tag)

                # Remove tags that were removed on remote media
                for t in existing_tags - tags_on_media:
                    namespace, name = t
                    tag = Tag.objects.get(name=name, namespace=namespace)
                    media.tags.remove(tag)

    except CommandError:
        pass