# Path: lib/crypto/packaged.py
# def sign_app(src, dest, ids, reviewer=False, local=False):
#     """
#     Sign a packaged app.
# 
#     If `local` is True, we never copy the signed package to remote storage.
# 
#     """
#     tempname = tempfile.mktemp()
#     try:
#         return _sign_app(src, dest, ids, reviewer, tempname, local)
#     finally:
#         try:
#             os.unlink(tempname)
#         except OSError:
#             # If the file has already been removed, don't worry about it.
#             pass
# 
# class SigningError(Exception):
#     pass


import json
import os.path
import commonware.log
from uuid import UUID
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.functional import lazy
from django_statsd.clients import statsd
from uuidfield.fields import UUIDField
from lib.crypto.packaged import sign_app, SigningError
from mkt.files.models import cleanup_file, nfd_str
from mkt.langpacks.utils import LanguagePackParser
from mkt.translations.utils import to_language
from mkt.site.helpers import absolutify
from mkt.site.models import ModelBase
from mkt.site.storage_utils import private_storage, public_storage
from mkt.site.utils import smart_path
from mkt.webapps.models import get_cached_minifest
# -*- coding: utf-8 -*-





log = commonware.log.getLogger('z.versions')


def _make_language_choices(languages):
    return [(to_language(lang_code), lang_name)
            for lang_code, lang_name in languages.items()]


LANGUAGE_CHOICES = lazy(_make_language_choices, list)(settings.LANGUAGES)


class LangPack(ModelBase):
    # Primary key is a uuid in order to be able to set it in advance (we need
    # something unique for the filename, and we don't have a slug).
    uuid = UUIDField(primary_key=True, auto=True)

    # Fields for which the manifest is the source of truth - can't be
    # overridden by the API.
    language = models.CharField(choices=LANGUAGE_CHOICES,
                                default=settings.LANGUAGE_CODE,
                                max_length=10)
    fxos_version = models.CharField(max_length=255, default='')

# Path: lib/crypto/packaged.py
# def sign_app(src, dest, ids, reviewer=False, local=False):
#     """
#     Sign a packaged app.
# 
#     If `local` is True, we never copy the signed package to remote storage.
# 
#     """
#     tempname = tempfile.mktemp()
#     try:
#         return _sign_app(src, dest, ids, reviewer, tempname, local)
#     finally:
#         try:
#             os.unlink(tempname)
#         except OSError:
#             # If the file has already been removed, don't worry about it.
#             pass
# 
# class SigningError(Exception):
#     pass


# Path: mkt/langpacks/models.py
import json
import os.path
import commonware.log
from uuid import UUID
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.functional import lazy
from django_statsd.clients import statsd
from uuidfield.fields import UUIDField
from lib.crypto.packaged import sign_app, SigningError
from mkt.files.models import cleanup_file, nfd_str
from mkt.langpacks.utils import LanguagePackParser
from mkt.translations.utils import to_language
from mkt.site.helpers import absolutify
from mkt.site.models import ModelBase
from mkt.site.storage_utils import private_storage, public_storage
from mkt.site.utils import smart_path
from mkt.webapps.models import get_cached_minifest

# -*- coding: utf-8 -*-





log = commonware.log.getLogger('z.versions')


def _make_language_choices(languages):
    return [(to_language(lang_code), lang_name)
            for lang_code, lang_name in languages.items()]


LANGUAGE_CHOICES = lazy(_make_language_choices, list)(settings.LANGUAGES)


class LangPack(ModelBase):
    # Primary key is a uuid in order to be able to set it in advance (we need
    # something unique for the filename, and we don't have a slug).
    uuid = UUIDField(primary_key=True, auto=True)

    # Fields for which the manifest is the source of truth - can't be
    # overridden by the API.
    language = models.CharField(choices=LANGUAGE_CHOICES,
                                default=settings.LANGUAGE_CODE,
                                max_length=10)
    fxos_version = models.CharField(max_length=255, default='')

    version = models.CharField(max_length=255, default='')