Ejemplo n.º 1
0
def cmd_upload(args):
    # TODO: fix upload to web interface
    if not os.path.exists(COMO_BATTERY_FILE):
        error("No como database.")
    else:
        if is_osx:
            url = SERVER_URL + "/upload"
            cmd = "ioreg -l | awk '/IOPlatformSerialNumber/ " + \
                  "{ split($0, line, \"\\\"\"); printf(\"%s\\n\", line[4]); }'"
            computer_serial = subprocess.check_output(
                cmd, shell=True).translate(None, '\n')
            bat = get_battery()
            model = subprocess.check_output(
                "sysctl -n hw.model", shell=True).rstrip("\n")
            data = {
                'computer': hashlib.md5(computer_serial).hexdigest(),
                'model': model,
                'battery': hashlib.md5(bat['serial']).hexdigest(),
                'design': bat['designcap'],
                'age': get_age()
            }
            files = {'como': open(COMO_BATTERY_FILE, 'rb')}
            response = requests.post(url, files=files, data=data)
            if response.status_code == requests.codes.ok:
                puts("data uploaded")
            else:
                puts("upload failed")
        else:
            message("no uploading on this operating system")
Ejemplo n.º 2
0
def cmd_upload(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        error("No como database.")
    else:
        if is_osx:
            url = SERVER_URL + "/upload"
            cmd = "ioreg -l | awk '/IOPlatformSerialNumber/ " + \
                  "{ split($0, line, \"\\\"\"); printf(\"%s\\n\", line[4]); }'"
            computer_serial = subprocess.check_output(
                cmd, shell=True).translate(None, '\n')
            bat = get_battery()
            model = subprocess.check_output(
                "sysctl -n hw.model", shell=True).rstrip("\n")
            data = {
                'computer': hashlib.md5(computer_serial).hexdigest(),
                'model': model,
                'battery': hashlib.md5(bat['serial']).hexdigest(),
                'design': bat['designcap'],
                'age': get_age()
            }
            files = {'como': open(COMO_BATTERY_FILE, 'rb')}
            response = requests.post(url, files=files, data=data)
            if response.status_code == requests.codes.ok:
                puts("data uploaded")
            else:
                puts("upload failed")
        else:
            message("no uploading on this operating system")
Ejemplo n.º 3
0
def cmd_export(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        error("No como database.")
    else:
        if os.path.exists("como.csv"):
            sure = raw_input(
                "Do you want to replace the old export file (como.csv)?" +
                " [y/n] ")
            if sure != 'y':
                return
        dataset = read_database()
        with open("como.csv", "w") as como:
            como.write(dataset.csv)
        message("saved file to current directory")
Ejemplo n.º 4
0
def cmd_export(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        error("No como database.")
    else:
        if os.path.exists("como.csv"):
            sure = raw_input(
                "Do you want to replace the old export file (como.csv)?" +
                " [y/n] ")
            if sure != 'y':
                return
        dataset = read_database()
        with open("como.csv", "w") as como:
            como.write(dataset.csv)
        message("saved file to current directory")
Ejemplo n.º 5
0
def cmd_save(args):
    bat = get_battery()

    if not os.path.exists(COMO_BATTERY_FILE):
        data = create_database()
    else:
        data = read_database()
    if is_win:
        bat['cycles'] = None
    data.append([
        datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"),
        bat['maxcap'],
        bat['cycles'],
    ])

    with open(COMO_BATTERY_FILE, 'w') as como:
        como.write(zlib.compress(data.json))

    message("battery info saved (%s)" % str(data['time'][-1]))
Ejemplo n.º 6
0
def cmd_save(args):
    bat = get_battery()

    if not os.path.exists(COMO_BATTERY_FILE):
        data = create_database()
    else:
        data = read_database()
    if is_win:
        bat['cycles'] = None
    data.append([
        datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"),
        bat['maxcap'],
        bat['cycles'],
    ])

    with open(COMO_BATTERY_FILE, 'w') as como:
        como.write(zlib.compress(data.json))

    message("battery info saved (%s)" % str(data['time'][-1]))