コード例 #1
0
 def js_mkdir():
     """Register a MKDIR job."""
     site = request.data['sitename']
     if site not in current_app.site_map:
         abort(404, description="Site not known.")
     token = flask.session['token']
     tclient = TransferClient(token)
     tclient.mkdir(site, request.data['dst_filepath'])
     return '', 200
コード例 #2
0
 def element_output(job_id, element_id):
     """Get output for element from a given user's job."""
     token = flask.session['token']
     tclient = TransferClient(token)
     attempts = []
     try:
         attempts = tclient.output(job_id, element_id)[0]
     except RESTException:
         flash("no attempts", "warning")
     return render_template("output_carousel.html", attempts=attempts)
コード例 #3
0
 def js_copy():
     """Resister a COPY job."""
     src_site = request.data['src_sitename']
     if src_site not in current_app.site_map:
         abort(404, description="Source site not known.")
     dst_site = request.data['dst_sitename']
     if dst_site not in current_app.site_map:
         abort(404, description="Destination site not known.")
     token = flask.session['token']
     tclient = TransferClient(token)
     tclient.copy(src_site,
                  request.data['src_filepath'],
                  dst_site,
                  request.data['dst_filepath'],
                  overwrite=request.data.get("overwrite", False))
     return '', 200
コード例 #4
0
    def js_list():
        """List a directory."""
        sitename = request.data['sitename']
        filepath = request.data['filepath']
        site = current_app.site_map.get(sitename)
        if site is None:
            abort(404, description="Site %s not found" % sitename)
        token = flask.session['token']
        current_app.siteclient.set_token(token)
        session_info = current_app.siteclient.get_session_info(site['site_id'])
        if not session_info['ok']:
            vos = []
            voms_auth = current_app.siteclient.get_site(
                site['site_id'])['auth_type']
            if voms_auth:
                vos = current_app.siteclient.get_service_info().get('vos', [])
                if not vos:
                    flash(
                        "No VOs registered, contact your system administrator!",
                        "danger")
                    current_app.log.warning(
                        "No VOs returned by get_service_info.")
            return render_template("loginform.html",
                                   sitename=sitename,
                                   voms_auth=voms_auth,
                                   vos=vos), 403

        tclient = TransferClient(token)
        jobinfo = tclient.list(sitename, filepath, depth=1)

        listing_output = []
        if jobinfo:
            time.sleep(1)
            status = tclient.status(jobinfo['id'])
            while status['status'] not in ('DONE', 'FAILED'):
                time.sleep(1)  # seconds
                status = tclient.status(jobinfo['id'])

            if status['status'] == 'DONE':
                listing_output = [
                    dict(f, is_dir=stat.S_ISDIR(f['st_mode']))
                    for f in tclient.output(jobinfo['id'], 0, -1)[0][0]
                    ['listing'].values()[0]
                ]
            elif jobinfo['status'] == 'FAILED':
                current_app.log.error("Failed to obtain a listing for job %d",
                                      jobinfo['id'])
            else:
                current_app.log.warning(
                    "Timeout. Last status is %s for job id %d",
                    status['status'], jobinfo['id'])

        return json.dumps(listing_output)
コード例 #5
0
 def elements(job_id):
     """List elements for a given user's job."""
     token = flask.session['token']
     tclient = TransferClient(token)
     elements = tclient.elements(job_id)
     return json.dumps(elements)
コード例 #6
0
 def jobs():
     """List a user's jobs."""
     token = flask.session['token']
     tclient = TransferClient(token)
     return json.dumps(tclient.jobs())