Esempio n. 1
0
def save_publication(self, project_id):
    from designsafe.apps.api.agave.filemanager.public_search_index import Publication
    from designsafe.apps.api.projects.managers import publication as PublicationManager
    try:
        pub = Publication(project_id=project_id)
        publication = PublicationManager.reserve_publication(pub.to_dict())
        pub.update(**publication)
    except Exception as exc:
        logger.error('Proj Id: %s. %s', project_id, exc, exc_info=True)
        raise self.retry(exc=exc)
Esempio n. 2
0
def save_to_fedora(self, project_id):
    import requests
    import magic
    from designsafe.apps.api.agave.filemanager.public_search_index import Publication
    try:
        pub = Publication(project_id=project_id)
        pub.update(status='published')
        _root = os.path.join('/corral-repl/tacc/NHERI/published', project_id)
        fedora_base = 'http://fedoraweb01.tacc.utexas.edu:8080/fcrepo/rest/publications_01'
        res = requests.get(fedora_base)
        if res.status_code == 404 or res.status_code == 410:
            requests.put(fedora_base)

        fedora_project_base = ''.join([fedora_base, '/', project_id])
        res = requests.get(fedora_project_base)
        if res.status_code == 404 or res.status_code == 410:
            requests.put(fedora_project_base)

        headers = {'Content-Type': 'text/plain'}
        #logger.debug('walking: %s', _root)
        for root, dirs, files in os.walk(_root):
            for name in files:
                mime = magic.Magic(mime=True)
                headers['Content-Type'] = mime.from_file(
                    os.path.join(root, name))
                #files
                full_path = os.path.join(root, name)
                _path = full_path.replace(_root, '', 1)
                _path = _path.replace('[', '-')
                _path = _path.replace(']', '-')
                url = ''.join([fedora_project_base, urllib.quote(_path)])
                #logger.debug('uploading: %s', url)
                with open(os.path.join(root, name), 'rb') as _file:
                    requests.put(url, data=_file, headers=headers)

            for name in dirs:
                #dirs
                full_path = os.path.join(root, name)
                _path = full_path.replace(_root, '', 1)
                url = ''.join([fedora_project_base, _path])
                #logger.debug('creating: %s', _path)
                requests.put(url)

    except Exception as exc:
        logger.error('Proj Id: %s. %s', project_id, exc)
        raise self.retry(exc=exc)
Esempio n. 3
0
def set_publish_status(self, project_id):
    from designsafe.apps.api.agave.filemanager.public_search_index import Publication
    pub = Publication(project_id=project_id)
    pub.update(status='published')