Skip to content

Commit

Permalink
Move extract_content_db to i18n.base.
Browse files Browse the repository at this point in the history
  • Loading branch information
aronasorman committed Mar 8, 2016
1 parent 8aa4d4d commit dba86fc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
26 changes: 2 additions & 24 deletions kalite/distributed/management/commands/retrievecontentpack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil
import tempfile
import urllib
import zipfile

from optparse import make_option
Expand All @@ -15,8 +14,8 @@

from kalite.contentload import settings as content_settings
from kalite.i18n.base import lcode_to_django_lang, get_po_filepath, get_locale_path, \
download_content_pack, update_jsi18n_file, get_srt_path as get_subtitle_path
from kalite.topic_tools import settings
download_content_pack, update_jsi18n_file, get_srt_path as get_subtitle_path, \
extract_content_db
from kalite.updates.management.commands.classes import UpdatesStaticCommand

logging = django_settings.LOG
Expand Down Expand Up @@ -147,27 +146,6 @@ def extract_catalog_files(zf, lang):
shutil.copyfileobj(zipmof, djangomof)


def extract_content_db(zf, lang, is_template=False):
"""
:param: as_template: Extracts the result to the template destination,
intended for source distribution
"""
if not is_template:
content_db_path = settings.CONTENT_DATABASE_PATH.format(
channel=settings.CHANNEL,
language=lang,
)
else:
content_db_path = settings.CONTENT_DATABASE_TEMPLATE_PATH.format(
channel=settings.CHANNEL,
language=lang,
)

with open(content_db_path, "wb") as f:
dbfobj = zf.open("content.db")
shutil.copyfileobj(dbfobj, f)


def extract_subtitles(zf, lang):
SUBTITLE_DEST_DIR = get_subtitle_path(lang_code=lang)
SUBTITLE_ZIP_DIR = "subtitles/"
Expand Down
23 changes: 23 additions & 0 deletions kalite/i18n/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from contextlib import contextmanager

from kalite.version import VERSION, SHORTVERSION
from kalite.topic_tools import settings as topic_settings

from fle_utils.config.models import Settings
from fle_utils.general import ensure_dir, softload_json
Expand Down Expand Up @@ -381,3 +382,25 @@ def download_content_pack(fobj, lang, minimal=False):
httpf.close()

return zf


def extract_content_db(zf, lang, is_template=False):
"""
:param: as_template: Extracts the result to the template destination,
intended for source distribution
"""
if not is_template:
content_db_path = topic_settings.CONTENT_DATABASE_PATH.format(
channel=topic_settings.CHANNEL,
language=lang,
)
else:
content_db_path = topic_settings.CONTENT_DATABASE_TEMPLATE_PATH.format(
channel=topic_settings.CHANNEL,
language=lang,
)

with open(content_db_path, "wb") as f:
dbfobj = zf.open("content.db")
shutil.copyfileobj(dbfobj, f)

0 comments on commit dba86fc

Please sign in to comment.