Exemplo n.º 1
0
Arquivo: app.py Projeto: TurpIF/KHome
def api_upload_module():
    file_ = request.files['file']
    if not file_:
        abort(400)
    if not allowed_file(file_.filename, ['zip']):
        abort(403)

    # all is good, let's go !
    _, filename = tempfile.mkstemp()
    file_.save(filename)
    try:
        packaging.install_from_zip(filename)
    except (IOError, ValueError):
        abort(403)
    finally:
        try:
            os.remove(filename)
        except OSError:
            pass
    return ''
Exemplo n.º 2
0
def api_upload_module():
    file_ = request.files['file']
    if not file_:
        abort(400)
    if not allowed_file(file_.filename, ['zip']):
        abort(403)

    # all is good, let's go !
    _, filename = tempfile.mkstemp()
    file_.save(filename)
    try:
        packaging.install_from_zip(filename)
    except (IOError, ValueError):
        abort(403)
    finally:
        try:
            os.remove(filename)
        except OSError:
            pass
    return ''
Exemplo n.º 3
0
Arquivo: app.py Projeto: TurpIF/KHome
def api_install_module(module_name):
    try:
        io = StringIO()
        zipfile = urllib2.urlopen(urlparse.urljoin(STORE_URL,
            '/api/available_modules/%s/download' % module_name))
        io.write(zipfile.read())
        success = packaging.install_from_zip(io)
    except urllib2.HTTPError:
        abort(404)
    except IOError:
        abort(403)
    return jsonify({ 'success': success })
Exemplo n.º 4
0
def api_install_module(module_name):
    try:
        io = StringIO()
        zipfile = urllib2.urlopen(
            urlparse.urljoin(
                STORE_URL, '/api/available_modules/%s/download' % module_name))
        io.write(zipfile.read())
        success = packaging.install_from_zip(io)
    except urllib2.HTTPError:
        abort(404)
    except IOError:
        abort(403)
    return jsonify({'success': success})