# Path: kano_apps/utils.py
# def get_dpkg_dict(include_unpacked=False):
#     apps_ok = dict()
#     apps_other = dict()
# 
#     cmd = 'dpkg -l'
#     o, _, _ = run_cmd(cmd)
#     lines = o.splitlines()
#     for l in lines[5:]:
#         parts = l.split()
#         state = parts[0]
#         name = parts[1]
#         version = parts[2]
# 
#         if state == 'ii' or (include_unpacked and state == 'iU'):
#             apps_ok[name] = version
#         else:
#             apps_other[name] = version
# 
#     return apps_ok, apps_other


import os
import json
import time
import requests
from kano_apps.utils import get_dpkg_dict
from kano.utils import run_cmd, download_url, has_min_performance
from kano_world.config import load_conf
    # make sure there are no broken packages on the system
    run_cmd(cleanup_cmd)

    run_cmd(update_cmd)
    os.system(cmd.encode('utf8'))

    done = True
    installed_packages = get_dpkg_dict()[0]
    for pkg in app["packages"] + app["dependencies"]:
        if pkg not in installed_packages:
            done = False
            break

    return done


def uninstall_packages(app, sudo_pwd=None):
    if len(app["packages"]) == 0:
        return True

    pkgs = " ".join(app["packages"])

    cmd = ("rxvt -title " + _("'Uninstalling {}'") + " -e bash -c ").format(app["title"])
    if sudo_pwd:
        cmd += "'echo {} | sudo -S apt-get purge -y {}'".format(sudo_pwd, pkgs)
    else:
        cmd += "'sudo apt-get purge -y {}'".format(pkgs, sudo_pwd)
    os.system(cmd.encode('utf8'))

    done = True

# Path: kano_apps/utils.py
# def get_dpkg_dict(include_unpacked=False):
#     apps_ok = dict()
#     apps_other = dict()
# 
#     cmd = 'dpkg -l'
#     o, _, _ = run_cmd(cmd)
#     lines = o.splitlines()
#     for l in lines[5:]:
#         parts = l.split()
#         state = parts[0]
#         name = parts[1]
#         version = parts[2]
# 
#         if state == 'ii' or (include_unpacked and state == 'iU'):
#             apps_ok[name] = version
#         else:
#             apps_other[name] = version
# 
#     return apps_ok, apps_other


# Path: kano_apps/AppManage.py
import os
import json
import time
import requests
from kano_apps.utils import get_dpkg_dict
from kano.utils import run_cmd, download_url, has_min_performance
from kano_world.config import load_conf

    # make sure there are no broken packages on the system
    run_cmd(cleanup_cmd)

    run_cmd(update_cmd)
    os.system(cmd.encode('utf8'))

    done = True
    installed_packages = get_dpkg_dict()[0]
    for pkg in app["packages"] + app["dependencies"]:
        if pkg not in installed_packages:
            done = False
            break

    return done


def uninstall_packages(app, sudo_pwd=None):
    if len(app["packages"]) == 0:
        return True

    pkgs = " ".join(app["packages"])

    cmd = ("rxvt -title " + _("'Uninstalling {}'") + " -e bash -c ").format(app["title"])
    if sudo_pwd:
        cmd += "'echo {} | sudo -S apt-get purge -y {}'".format(sudo_pwd, pkgs)
    else:
        cmd += "'sudo apt-get purge -y {}'".format(pkgs, sudo_pwd)
    os.system(cmd.encode('utf8'))

    done = True

    installed_packages = get_dpkg_dict()[0]