示例#1
0
def system_shutdown():
    with sh.sudo:
        try:
            sh.sync()
            sh.halt()
        except sh.ErrorReturnCode_1:
            flash('Unable to shutdown device!', 'error')
            return redirect(url_for('settings.host'))

    flash('Shutting device down!', 'success')
    return redirect(url_for('settings.host'))
示例#2
0
def system_shutdown():
    with sh.sudo:
        try:
            sh.sync()
            sh.halt()
        except sh.ErrorReturnCode_1:
            flash('Unable to shutdown device!', 'error')
            return redirect(url_for('settings.host'))

    flash('Shutting device down!', 'success')
    return redirect(url_for('settings.host'))
示例#3
0
文件: web.py 项目: wie-niet/gps-hub
def pageAction():
    # redirect all GET requests back to the main index
    if request.method != 'POST':
        return redirect(url_for('index'))

    # action nothing: redirect back to index
    if request.form['action'] == "nothing":
        return redirect(url_for('index'))

    # action mount usb disk
    if request.form['action'] == "mount":
        gps.mount()
        return redirect(url_for('index'))

    # action read GarminDevice.xml config file
    elif request.form['action'] == "read_device_xml":
        gps.readGarminDeviceXml()
        return redirect(url_for('index'))

    # action umount usb disk (a.k.a. eject )
    elif request.form['action'] == "umount":
        gps.umount()
        return redirect(url_for('index'))

    # action bring system to a proper halt
    elif request.form['action'] == "system_halt":
        if gps.isMounted() is False:
            if gps.isDevExists() is False:
                # let's add an extra step
                if gps.halt_secret == int(request.form['halt_secret']):
                    sh.halt()
                    return """ system going for halt """
                else:
                    # generate a temporary halt_secret
                    gps.halt_secret = random.randint(0, 10e10)
                    return render_template('halt.html',
                                           halt_secret=gps.halt_secret)

            else:
                return """ gps is still conected """
        else:
            return """ gps is still mounted """

    # action upload file
    elif request.form['action'] == "file_upload":
        folderName = request.form['folder_name']
        uploadPath = gps.getFolderPathByName(folderName)
        extension = gps.getFolderExtensionByName(folderName)

        file = request.files['file']
        if file and file.filename.lower().endswith('.' + extension.lower()):
            filename = secure_filename(file.filename)
            if os.path.exists(os.path.join(uploadPath, filename)):
                return """error: filename already exists..."""

            file.save(os.path.join(uploadPath, filename))
            return redirect(url_for('index'))
        else:
            return """error: no valid file ..."""

    # action download file
    elif request.form['action'] == "file_download":
        folderName = request.form['folder_name']
        fileName = request.form['file_name']

        return send_file(os.path.join(gps.getFolderPathByName(folderName),
                                      fileName),
                         as_attachment=True,
                         attachment_filename=os.path.basename(fileName))

    # action invalid
    else:
        return """error: no valid action given..."""