예제 #1
0
파일: asset.py 프로젝트: bartbes/CubeCreate
    def get_by_path(asset_path, check_master=True):
        data = AssetMetadata.load_raw(
            AssetMetadata.get_metadata_path(asset_path))
        if data is not None:
            return AssetMetadata(data['asset_id'])
        else:
            if not check_master:
                raise Exception(
                    "Cannot get metadata for asset %s as an error occured in reading"
                    % asset_path)

            # Try to scrape the master - hackish scraping
            try:
                log(
                    logging.WARNING,
                    "Trying to scrape master for asset metadata for %s" %
                    asset_path)

                import sys, traceback
                from intensity.master import get_master_server
                import intensity.components.thirdparty.BeautifulSoup as BeautifulSoup

                html = urllib.urlopen('http://' + get_master_server() +
                                      '/tracker/assets/').read()
                results = []
                soup = BeautifulSoup.BeautifulSoup(html)
                trs = soup.findAll('tr')
                for tr in trs:
                    if 'tracker/asset' in str(tr.contents):
                        try:
                            result = {
                                'location':
                                str(tr.contents[1].contents[0].contents[0]),
                                'url':
                                str(tr.contents[1].contents[0].attrs[0][1])
                            }
                            if 'data/' + result['location'] == asset_path:
                                results.append(result)
                        except Exception, e:
                            traceback.print_exc(file=sys.stdout)
                            pass
                if len(results) == 0:
                    raise Exception(
                        "Could not find that asset, even on the master")
                elif len(results) > 1:
                    raise Exception("Found more than 1 relevant assets: %s" %
                                    str(results))
                asset_id = results[0]['url'].split('/')[-2]
                AssetManager.acquire(asset_id)
                return AssetMetadata.get_by_path(asset_path, False)
            except Exception, e:
                traceback.print_exc(file=sys.stdout)
                log(
                    logging.WARNING,
                    "Tried to scrape master for asset metadata for %s, but failed due to: %s"
                    % (asset_path, str(e)))
                raise
예제 #2
0
파일: asset.py 프로젝트: bartbes/CubeCreate
        def side_operations():
            params = [
                ('asset_id', asset_info.asset_id),
                ('user_id', get_master_session().my_id),
                ('return_to', 'http://' + get_master_server()
                 )  # asset server detects master from this
            ]

            get_master_session().add_info(params)  # Add session info

            try:
                Output.response = post_multipart(protocol, asset_server, path,
                                                 params,
                                                 [('file', "Xx.xX", data)])
            except Exception, e:
                Output.response = None
                Output.error = "Error in uploading asset: %s" % (str(e))
예제 #3
0
파일: asset.py 프로젝트: bartbes/CubeCreate
    def get_by_path(asset_path, check_master=True):
        data = AssetMetadata.load_raw( AssetMetadata.get_metadata_path(asset_path) )
        if data is not None:
            return AssetMetadata(data['asset_id'])
        else:
            if not check_master:
                raise Exception("Cannot get metadata for asset %s as an error occured in reading" % asset_path)

            # Try to scrape the master - hackish scraping
            try:
                log(logging.WARNING, "Trying to scrape master for asset metadata for %s" % asset_path)

                import sys, traceback
                from intensity.master import get_master_server
                import intensity.components.thirdparty.BeautifulSoup as BeautifulSoup

                html = urllib.urlopen('http://' + get_master_server() + '/tracker/assets/').read()
                results = []
                soup = BeautifulSoup.BeautifulSoup(html)
                trs = soup.findAll('tr')
                for tr in trs:
                    if 'tracker/asset' in str(tr.contents):
                        try:
                            result = {
                                'location': str(tr.contents[1].contents[0].contents[0]),
                                'url': str(tr.contents[1].contents[0].attrs[0][1])
                            }
                            if 'data/' + result['location'] == asset_path:
                                results.append(result)
                        except Exception, e:
                            traceback.print_exc(file=sys.stdout)
                            pass
                if len(results) == 0:
                    raise Exception("Could not find that asset, even on the master")
                elif len(results) > 1:
                    raise Exception("Found more than 1 relevant assets: %s" % str(results))
                asset_id = results[0]['url'].split('/')[-2]
                AssetManager.acquire(asset_id)
                return AssetMetadata.get_by_path(asset_path, False)
            except Exception, e:
                traceback.print_exc(file=sys.stdout)
                log(logging.WARNING, "Tried to scrape master for asset metadata for %s, but failed due to: %s" % (
                    asset_path, str(e)
                ))
                raise
예제 #4
0
def autodiscover_activity(activity_id):
    if get_config('Network', 'master_server', '') == '':
        return '', ''

    if '/' in activity_id:
        activity_id = re.search('/(\w+)/$', activity_id).group(1)

    # Get the map asset ID using a request to the master
    log(logging.DEBUG, 'Contacting master to find map asset ID for activity %s' % activity_id)
    conn = httplib.HTTPConnection(get_master_server())
    conn.request('GET', '/tracker/activity/view/%s/' % activity_id)
    response = conn.getresponse()
    assert(response.status == 200)
    data = response.read()
    conn.close()

    map_asset_id = re.search('asset/view/(\w+)/', data).group(1)

    return activity_id, map_asset_id
예제 #5
0
def autodiscover_activity(activity_id):
    if get_config('Network', 'master_server', '') == '':
        return '', ''

    if '/' in activity_id:
        activity_id = re.search('/(\w+)/$', activity_id).group(1)

    # Get the map asset ID using a request to the master
    log(logging.DEBUG, 'Contacting master to find map asset ID for activity %s' % activity_id)
    conn = httplib.HTTPConnection(get_master_server())
    conn.request('GET', '/tracker/activity/view/%s/' % activity_id)
    response = conn.getresponse()
    assert(response.status == 200)
    data = response.read()
    conn.close()

    map_asset_id = re.search('asset/view/(\w+)/', data).group(1)

    return activity_id, map_asset_id
예제 #6
0
파일: asset.py 프로젝트: bartbes/CubeCreate
        def side_operations():
            params = [
                ('asset_id', asset_info.asset_id),
                ('user_id', get_master_session().my_id),
                ('return_to', 'http://' + get_master_server()) # asset server detects master from this
            ]

            get_master_session().add_info(params) # Add session info

            try:
                Output.response = post_multipart(
                    protocol,
                    asset_server,
                    path,
                    params,
                    [ ('file', "Xx.xX", data) ]
                )
            except Exception, e:
                Output.response = None
                Output.error = "Error in uploading asset: %s" % (str(e))