示例#1
0
文件: core.py 项目: cwoebker/como
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")
示例#2
0
文件: core.py 项目: stuartphilp/como
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")
示例#3
0
文件: core.py 项目: cwoebker/como
def auto_upload():
    apple_plist = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" """ + \
""" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.cwoebker.como-update</string>
    <key>OnDemand</key>
    <true/>
    <key>RunAtLoad</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>%s</string>
        <string>upload</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key>
      <integer>11</integer>
      <key>Minute</key>
      <integer>0</integer>
    </dict>
</dict>
</plist>"""
    if is_osx:
        plist_path = os.path.expanduser(
            "~/Library/LaunchAgents/com.cwoebker.como-update.plist")
        if os.path.exists(plist_path):
            os.system("launchctl unload %s" % plist_path)
            os.remove(plist_path)
            puts(colored.white("como will not upload data"))
        else:
            with open(plist_path, "w") as plist_file:
                plist_file.write(
                    apple_plist % os.popen('which como').read().rstrip('\n'))
            os.system("launchctl load %s" % plist_path)
            puts(colored.white("como will automatically upload the data"))
    elif is_lin:
        user_cron = CronTab()
        user_cron.read()
        if len(user_cron.find_command("como-update")) > 0:
            user_cron.remove_all("como-update")
            user_cron.write()
            puts(colored.white("como will not upload data"))
        else:
            job = user_cron.new(command="como-update")
            job.minute.every(2)
            #job.minute.on(0)
            #job.hour.on(19)
            user_cron.write()
            puts(colored.white("como will automatically upload the data"))
    elif is_win:
        error("Sorry there is no auto-upload for windows.")
示例#4
0
文件: core.py 项目: stuartphilp/como
def auto_upload():
    apple_plist = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" """ + \
""" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.cwoebker.como-update</string>
    <key>OnDemand</key>
    <true/>
    <key>RunAtLoad</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>%s</string>
        <string>upload</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
      <key>Hour</key>
      <integer>11</integer>
      <key>Minute</key>
      <integer>0</integer>
    </dict>
</dict>
</plist>"""
    if is_osx:
        plist_path = os.path.expanduser(
            "~/Library/LaunchAgents/com.cwoebker.como-update.plist")
        if os.path.exists(plist_path):
            os.system("launchctl unload %s" % plist_path)
            os.remove(plist_path)
            puts(colored.white("como will not upload data"))
        else:
            with open(plist_path, "w") as plist_file:
                plist_file.write(
                    apple_plist % os.popen('which como').read().rstrip('\n'))
            os.system("launchctl load %s" % plist_path)
            puts(colored.white("como will automatically upload the data"))
    elif is_lin:
        user_cron = CronTab()
        user_cron.read()
        if len(user_cron.find_command("como-update")) > 0:
            user_cron.remove_all("como-update")
            user_cron.write()
            puts(colored.white("como will not upload data"))
        else:
            job = user_cron.new(command="como-update")
            job.minute.every(2)
            #job.minute.on(0)
            #job.hour.on(19)
            user_cron.write()
            puts(colored.white("como will automatically upload the data"))
    elif is_win:
        error("Sorry there is no auto-upload for windows.")
示例#5
0
文件: core.py 项目: cwoebker/como
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")
示例#6
0
文件: core.py 项目: stuartphilp/como
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")
示例#7
0
文件: core.py 项目: cwoebker/como
def cmd_import(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        current_dataset = create_database()
    else:
        current_dataset = read_database()
    if os.path.exists(args.get(0)):
        import_dataset = Dataset()
        with open(os.path.expanduser(args.get(0)), "r") as import_file:
            import_dataset.csv = import_file.read()
        import_dataset.dict = map(import_format, import_dataset.dict)
        new = current_dataset.stack(import_dataset).sort('time')

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

        puts(colored.white("battery statistics imported"))
    else:
        error("Couldn't open file: %s" % args.get(0))
示例#8
0
文件: core.py 项目: stuartphilp/como
def cmd_import(args):
    if not os.path.exists(COMO_BATTERY_FILE):
        current_dataset = create_database()
    else:
        current_dataset = read_database()
    if os.path.exists(args.get(0)):
        import_dataset = Dataset()
        with open(os.path.expanduser(args.get(0)), "r") as import_file:
            import_dataset.csv = import_file.read()
        import_dataset.dict = map(import_format, import_dataset.dict)
        new = current_dataset.stack(import_dataset).sort('time')

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

        puts(colored.white("battery statistics imported"))
    else:
        error("Couldn't open file: %s" % args.get(0))
示例#9
0
文件: cli.py 项目: cwoebker/como
def main():
    if not supported:
        error("Your OS is not supported.")
        sys.exit(ExitStatus.UNSUPPORTED)
    app.go()
示例#10
0
文件: cli.py 项目: stuartphilp/como
def main():
    if not supported:
        error("Your OS is not supported.")
        sys.exit(ExitStatus.UNSUPPORTED)
    app.go()