Beispiel #1
0
def mocambola_post_save(instance, **kwargs):
    """Intercepta o sinal de *post_save* do Mocambola, serialize a adiciona o
    objeto ao repositorio."""

    serializer = UserSerializer(instance.user)
    mocambolapath = get_file_path(instance) + '/'
    mocamboladata = instance.user.get_username() + '.json'
    check_if_path_exists_or_create(mocambolapath)
    fout = open(mocambolapath + mocamboladata, 'w')
    fout.write(str(serializer.getJSON()))
    fout.close()
    git_add(mocamboladata, mocambolapath)
    git_commit(mocamboladata, instance.user.get_username(),
               instance.user.email, instance.repository.get_path())
Beispiel #2
0
def mocambola_post_save(instance, **kwargs):
    """Intercepta o sinal de *post_save* do Mocambola, serialize a adiciona o
    objeto ao repositorio."""

    serializer = UserSerializer(instance.user)
    mocambolapath = get_file_path(instance)+'/'
    mocamboladata = instance.user.get_username() + '.json'
    check_if_path_exists_or_create(mocambolapath)
    fout = open(mocambolapath + mocamboladata, 'w')
    fout.write(str(serializer.getJSON()))
    fout.close()
    git_add(mocamboladata, mocambolapath)
    git_commit(mocamboladata, instance.user.get_username(),
              instance.user.email, instance.repository.get_path())
Beispiel #3
0
    def request_copy(self, save=True):
        u"""
        Gera um pedido de copia local do media

        Os pedidos tem um codigo uuid e são gravados em 
        /repository/mucua/requests/uuid

        O arquivo atualmente contem somente o caminho para o media no
        repositorio.

        """
        self.set_is_local()
        if not self.is_local:
            self.is_requested = True
            if save:
                self.save()
            try:
                requests_path = os.path.join(REPOSITORY_DIR,
                                             self.get_repository(),
                                             DEFAULT_MUCUA, 'requests')
                if not os.path.exists(requests_path):
                    os.makedirs(requests_path)

                request_filename = os.path.join(requests_path, self.uuid)
                logger.info("REQUESTING: " + request_filename)
                request_file = open(request_filename, 'a')
                request_file.write(self.media_file.path)
                request_file.close
                # TODO: Need to git add
                logger.debug("ADDING REQUEST: " +
                             os.path.basename(request_filename))
                logger.debug("ADDED ON: " + os.path.dirname(request_filename))
                from repository.models import git_add
                git_add(os.path.basename(request_filename),
                        os.path.dirname(request_filename))

            except IOError:
                logger.info(u'Alo! I can\'t write request file!')

                logger.debug("get_file_path: " + get_file_path(self))
                logger.debug("media_file.name: " +
                             os.path.basename(self.media_file.name))

            async_result = git_annex_get.delay(
                get_file_path(self), os.path.basename(self.media_file.name))
Beispiel #4
0
    def request_copy(self, save=True):
        u"""
        Gera um pedido de copia local do media

        Os pedidos tem um codigo uuid e são gravados em 
        /repository/mucua/requests/uuid

        O arquivo atualmente contem somente o caminho para o media no
        repositorio.

        """
        self.set_is_local()
        if not self.is_local:
            self.is_requested = True
            if save:
                self.save()
            try:
                requests_path = os.path.join(REPOSITORY_DIR, self.get_repository(), 
                                                DEFAULT_MUCUA,
                                                'requests')
                if not os.path.exists(requests_path):
                    os.makedirs(requests_path)
                
                request_filename = os.path.join(requests_path, self.uuid)
                logger.info("REQUESTING: " + request_filename)
                request_file = open(request_filename, 'a')
                request_file.write(self.media_file.path)
                request_file.close
                # TODO: Need to git add
                logger.debug("ADDING REQUEST: " + os.path.basename(request_filename))
                logger.debug("ADDED ON: " + os.path.dirname(request_filename))
                from repository.models import git_add
                git_add(os.path.basename(request_filename), os.path.dirname(request_filename))
                
            except IOError:
                logger.info(u'Alo! I can\'t write request file!')
            
                logger.debug("get_file_path: " + get_file_path(self))
                logger.debug("media_file.name: " + os.path.basename(self.media_file.name))
        
            async_result = git_annex_get.delay(get_file_path(self), os.path.basename(self.media_file.name))
    def handle(self, *args, **options):
        repository = args[0]
        mucua = args[1]
        # Here we copy mucuas requests from all "linked mucuas" 
        linked_mucuas = git_remote_get_list(repository)
        requests_path = os.path.join(REPOSITORY_DIR, repository, mucua, "requests")
        if not os.path.exists(requests_path):
            os.makedirs(requests_path)

        for lmucua in linked_mucuas:
            lmucua_dir = os.path.join(REPOSITORY_DIR, repository, lmucua, "requests")
            if not os.path.isdir(lmucua_dir):
                os.mkdir(lmucua_dir)
            
            src_files = os.listdir(lmucua_dir)
            for file_name in src_files:
                full_file_name = os.path.join(lmucua_dir, file_name)
                if (os.path.isfile(full_file_name)):
                    shutil.copy(full_file_name, requests_path)
                    # TODO: Need to git add
                    logger.debug('ADDING REQUEST: ' + os.path.basename(full_file_name))
                    logger.debug('ADDED ON: ' + requests_path)
                    git_add(os.path.basename(full_file_name), requests_path)

        request_list = [uuid for uuid in os.listdir(requests_path)]

        for request_uuid in request_list:
            if os.path.isfile(os.path.join(requests_path, request_uuid)):
                try:
                    media = Media.objects.get(uuid=request_uuid)
                    media.set_is_local()
                    if media.is_local:
                        request_list = [uuid for uuid in request_list if uuid != request_uuid]
                        logger.debug('REMOVING REQUEST: ' + request_uuid)
                        git_rm(request_uuid, requests_path)
                        # Here we also git annex drop the file because
                        # it's only a "transport copy", couse of
                        # media.is_requested = False.
                        if not media.is_requested:
                            requests = []
                            # Check if we can drop, couse linked mucuas doesn't have pending request
                            for lmucua in linked_mucuas:
                                requests_path = os.path.join(REPOSITORY_DIR, 
                                                             repository, lmucua, "requests")
                                for name in os.listdir(requests_path):
                                    if os.path.isfile(os.path.join(requests_path, name)):
                                        requests.append(name)                        
                                        if request_uuid not in requests:
                                            # Check to see if origin mucua is not the current mucua
                                            if media.origin.description != mucua:
                                                # Doesn't work 
                                                #git_annex_drop(media)
                                                pass
                        else: 
                            media.is_requested = False                    
                        media.save()
                    else:
                        repository_path = os.path.join(REPOSITORY_DIR, media.get_repository())
                        async_result = git_annex_get.delay(get_file_path(media), 
                                                           os.path.basename(media.media_file.name))
                        logger.debug(async_result.info)
                        media.save()
                except Media.DoesNotExist:
                    logger.debug('Requested media not found: {0}'.format(request_uuid))
Beispiel #6
0
    def handle(self, *args, **options):
        repository = args[0]
        mucua = args[1]
        # Here we copy mucuas requests from all "linked mucuas"
        linked_mucuas = git_remote_get_list(repository)
        requests_path = os.path.join(REPOSITORY_DIR, repository, mucua,
                                     "requests")
        if not os.path.exists(requests_path):
            os.makedirs(requests_path)

        for lmucua in linked_mucuas:
            lmucua_dir = os.path.join(REPOSITORY_DIR, repository, lmucua,
                                      "requests")
            if not os.path.isdir(lmucua_dir):
                os.mkdir(lmucua_dir)

            src_files = os.listdir(lmucua_dir)
            for file_name in src_files:
                full_file_name = os.path.join(lmucua_dir, file_name)
                if (os.path.isfile(full_file_name)):
                    shutil.copy(full_file_name, requests_path)
                    # TODO: Need to git add
                    logger.debug('ADDING REQUEST: ' +
                                 os.path.basename(full_file_name))
                    logger.debug('ADDED ON: ' + requests_path)
                    git_add(os.path.basename(full_file_name), requests_path)

        request_list = [uuid for uuid in os.listdir(requests_path)]

        for request_uuid in request_list:
            if os.path.isfile(os.path.join(requests_path, request_uuid)):
                try:
                    media = Media.objects.get(uuid=request_uuid)
                    media.set_is_local()
                    if media.is_local:
                        request_list = [
                            uuid for uuid in request_list
                            if uuid != request_uuid
                        ]
                        logger.debug('REMOVING REQUEST: ' + request_uuid)
                        git_rm(request_uuid, requests_path)
                        # Here we also git annex drop the file because
                        # it's only a "transport copy", couse of
                        # media.is_requested = False.
                        if not media.is_requested:
                            requests = []
                            # Check if we can drop, couse linked mucuas doesn't have pending request
                            for lmucua in linked_mucuas:
                                requests_path = os.path.join(
                                    REPOSITORY_DIR, repository, lmucua,
                                    "requests")
                                for name in os.listdir(requests_path):
                                    if os.path.isfile(
                                            os.path.join(requests_path, name)):
                                        requests.append(name)
                                        if request_uuid not in requests:
                                            # Check to see if origin mucua is not the current mucua
                                            if media.origin.description != mucua:
                                                # Doesn't work
                                                #git_annex_drop(media)
                                                pass
                        else:
                            media.is_requested = False
                        media.save()
                    else:
                        repository_path = os.path.join(REPOSITORY_DIR,
                                                       media.get_repository())
                        async_result = git_annex_get.delay(
                            get_file_path(media),
                            os.path.basename(media.media_file.name))
                        logger.debug(async_result.info)
                        media.save()
                except Media.DoesNotExist:
                    logger.debug(
                        'Requested media not found: {0}'.format(request_uuid))