# 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 re
import json
from kano_settings.system.locale import get_locale, ensure_utf_locale
from kano_apps.utils import get_dpkg_dict
from kano_i18n.init import get_current_translation
# AppData.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Which apps to look for on the system



# The system directory that contains *.app and *.desktop entries
_SYSTEM_APPLICATIONS_LOC = '/usr/share/applications/'
DEFAULT_LOCALE = 'en_US'
LOCALE_KEY = 'locale'
APP_LOCALE_DIR = os.path.join(_SYSTEM_APPLICATIONS_LOC, 'locale')


# Store the package list globally so it doesn't get parsed every time
# we query for applications - it takes some time to parse it.
_INSTALLED_PKGS = get_dpkg_dict()[0]


def refresh_package_list():
    """ Reload the cached list of installed packages. """

    global _INSTALLED_PKGS


# 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/AppData.py
import os
import re
import json
from kano_settings.system.locale import get_locale, ensure_utf_locale
from kano_apps.utils import get_dpkg_dict
from kano_i18n.init import get_current_translation

# AppData.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Which apps to look for on the system



# The system directory that contains *.app and *.desktop entries
_SYSTEM_APPLICATIONS_LOC = '/usr/share/applications/'
DEFAULT_LOCALE = 'en_US'
LOCALE_KEY = 'locale'
APP_LOCALE_DIR = os.path.join(_SYSTEM_APPLICATIONS_LOC, 'locale')


# Store the package list globally so it doesn't get parsed every time
# we query for applications - it takes some time to parse it.
_INSTALLED_PKGS = get_dpkg_dict()[0]


def refresh_package_list():
    """ Reload the cached list of installed packages. """

    global _INSTALLED_PKGS


    _INSTALLED_PKGS = get_dpkg_dict()[0]