本文整理汇总了Python中kalite.settings.LOG.info方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.info方法的具体用法?Python LOG.info怎么用?Python LOG.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kalite.settings.LOG
的用法示例。
在下文中一共展示了LOG.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def handle(self, *args, **options):
# Check that we can run
if not settings.CENTRAL_SERVER:
raise CommandError("This must only be run on the central server.")
supported_langs = get_supported_languages()
if not options["lang_codes"]:
lang_codes = supported_langs
else:
requested_codes = set(options["lang_codes"].split(","))
lang_codes = [lcode_to_ietf(lc) for lc in requested_codes if lc in supported_langs]
unsupported_codes = requested_codes - set(lang_codes)
if unsupported_codes:
raise CommandError("Requested unsupported languages: %s" % sorted(list(unsupported_codes)))
# Scrub options
for key in options:
# If no_update is set, then disable all update options.
if key.startswith("update_"):
options[key] = options[key] and not options["no_update"]
if version_diff(options["version"], "0.10.3") < 0:
raise CommandError("This command cannot be used for versions before 0.10.3")
if options['low_mem']:
logging.info('Making the GC more aggressive...')
gc.set_threshold(36, 2, 2)
# For dealing with central server changes across versions
upgrade_old_schema()
# Now, we're going to build the language packs, collecting metadata long the way.
package_metadata = update_language_packs(lang_codes, options)
示例2: generate_test_files
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def generate_test_files():
"""Insert asterisks as translations in po files"""
# Open them up and insert asterisks for all empty msgstrs
logging.info("Generating test po files")
en_po_dir = os.path.join(settings.LOCALE_PATHS[0], "en/LC_MESSAGES/")
for po_file in glob.glob(os.path.join(en_po_dir, "*.po")):
msgid_pattern = re.compile(r'msgid \"(.*)\"\nmsgstr', re.S | re.M)
content = open(os.path.join(en_po_dir, po_file), 'r').read()
results = content.split("\n\n")
with open(os.path.join(en_po_dir, "tmp.po"), 'w') as temp_file:
# We know the first block is static, so just dump that.
temp_file.write(results[0])
# Now work through actual translations
for result in results[1:]:
try:
msgid = re.findall(msgid_pattern, result)[0]
temp_file.write("\n\n")
temp_file.write(result.replace("msgstr \"\"", "msgstr \"***%s***\"" % msgid))
except Exception as e:
logging.error("Failed to insert test string: %s\n\n%s\n\n" % (e, result))
# Once done replacing, rename temp file to overwrite original
os.rename(os.path.join(en_po_dir, "tmp.po"), os.path.join(en_po_dir, po_file))
(out, err, rc) = compile_po_files("en")
if err:
logging.debug("Error executing compilemessages: %s" % err)
示例3: update_metadata
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def update_metadata(package_metadata, version=VERSION):
"""
We've zipped the packages, and now have unzipped & zipped sizes.
Update this info in the local metadata (but not inside the zip)
"""
master_filepath = get_language_pack_availability_filepath(version=version)
master_metadata = softload_json(master_filepath, logger=logging.warn, errmsg="Error opening master language pack metadata")
for lc, updated_meta in package_metadata.iteritems():
lang_code_ietf = lcode_to_ietf(lc)
# Gather existing metadata
metadata_filepath = get_language_pack_metadata_filepath(lang_code_ietf, version=version)
stored_meta = softload_json(metadata_filepath, logger=logging.warn, errmsg="Error opening %s language pack metadata" % lc)
stored_meta.update(updated_meta)
# Write locally (this is used on download by distributed server to update it's database)
with open(metadata_filepath, 'w') as output:
json.dump(stored_meta, output)
# Update master (this is used for central server to handle API requests for data)
master_metadata[lang_code_ietf] = stored_meta
# Save updated master
ensure_dir(os.path.dirname(master_filepath))
with open(master_filepath, 'w') as output:
json.dump(master_metadata, output)
logging.info("Local record of translations updated")
示例4: handle
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def handle(self, *args, **options):
if len(args)==1 and args[0]== "test":
# Callback for "weak" test--checks at least that the django project compiles (local_settings is OK)
sys.stdout.write("Success!\n")
exit(0)
try:
if options.get("branch", None):
# Specified a repo
self.update_via_git(**options)
elif options.get("zip_file", None):
# Specified a file
if not os.path.exists(options.get("zip_file")):
raise CommandError("Specified zip file does not exist: %s" % options.get("zip_file"))
self.update_via_zip(**options)
elif options.get("url", None):
self.update_via_zip(**options)
elif os.path.exists(settings.PROJECT_PATH + "/../.git"):
# If we detect a git repo, try git
if len(args) == 1 and not options["branch"]:
options["branch"] = args[0]
elif len(args) != 0:
raise CommandError("Specified too many command-line arguments")
self.update_via_git(**options)
elif len(args) > 1:
raise CommandError("Too many command-line arguments.")
elif len(args) == 1:
# Specify zip via first command-line arg
if options['zip_file'] is not None:
raise CommandError("Cannot specify a zipfile as unnamed and named command-line arguments at the same time.")
options['zip_file'] = args[0]
self.update_via_zip(**options)
else:
# No params, no git repo: try to get a file online.
zip_file = tempfile.mkstemp()[1]
for url in ["http://%s/api/download/kalite/latest/%s/%s/" % (settings.CENTRAL_SERVER_HOST, platform.system().lower(), "en")]:
logging.info("Downloading repo snapshot from %s to %s" % (url, zip_file))
try:
urllib.urlretrieve(url, zip_file)
sys.stdout.write("success @ %s\n" % url)
break;
except Exception as e:
logging.debug("Failed to get zipfile from %s: %s" % (url, e))
continue
options["zip_file"] = zip_file
self.update_via_zip(**options)
except Exception as e:
if self.started() and not not self.ended():
self.cancel(stage_status="error", notes=unicode(e))
raise
assert self.ended(), "Subroutines should complete() if they start()!"
示例5: generate_fake_coachreport_logs
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def generate_fake_coachreport_logs(password="hellothere"):
t,_ = FacilityUser.objects.get_or_create(
facility=Facility.objects.all()[0],
username=random.choice(firstnames)
)
t.set_password(password)
# TODO: create flags later
num_logs = 20
logs = []
for _ in xrange(num_logs):
date_logged_in = datetime.datetime.now() - datetime.timedelta(days=random.randint(1,10))
date_viewed_coachreport = date_logged_in + datetime.timedelta(minutes=random.randint(0, 30))
date_logged_out = date_viewed_coachreport + datetime.timedelta(minutes=random.randint(0, 30))
login_log = UserLog.objects.create(
user=t,
activity_type=UserLog.get_activity_int("login"),
start_datetime=date_logged_in,
last_active_datetime=date_viewed_coachreport,
end_datetime=date_logged_out,
)
logging.info("created login log for teacher %s" % t.username)
coachreport_log = UserLog.objects.create(
user=t,
activity_type=UserLog.get_activity_int("coachreport"),
start_datetime=date_viewed_coachreport,
last_active_datetime=date_viewed_coachreport,
end_datetime=date_viewed_coachreport,
)
logs.append((login_log, coachreport_log))
logging.info("created coachreport log for teacher %s" % t.username)
return logs
示例6: handle
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def handle(self, *args, **options):
# Get the CSV data, either from a recent cache_file
# or from the internet
cache_dir = settings.MEDIA_ROOT
cache_file = os.path.join(cache_dir, "dubbed_videos.csv")
if not options["force"] and os.path.exists(cache_file) and datediff(datetime.datetime.now(), datetime.datetime.fromtimestamp(os.path.getctime(cache_file)), units="days") <= 14.0:
# Use cached data to generate the video map
csv_data = open(cache_file, "r").read()
(video_map, _) = generate_dubbed_video_mappings(csv_data=csv_data)
else:
# Use cached data to generate the video map
(video_map, csv_data) = generate_dubbed_video_mappings()
try:
ensure_dir(cache_dir)
with open(cache_file, "w") as fp:
fp.write(csv_data)
except Exception as e:
logging.error("Failed to make a local cache of the CSV data: %s" % e)
# Now we've built the map. Save it.
out_file = DUBBED_VIDEOS_MAPPING_FILEPATH
ensure_dir(os.path.dirname(out_file))
logging.info("Saving data to %s" % out_file)
with open(out_file, "w") as fp:
json.dump(video_map, fp)
logging.info("Done.")
示例7: handle_po_compile_errors
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def handle_po_compile_errors(lang_codes=None, out=None, err=None, rc=None):
"""
Return list of languages to not rezip due to errors in compile process.
Then email admins errors.
"""
broken_codes = re.findall(r'(?<=ka-lite/locale/)\w+(?=/LC_MESSAGES)', err) or []
if lang_codes:
# Only show the errors relevant to the list of language codes passed in.
lang_codes = set([lcode_to_django_dir(lc) for lc in lang_codes])
broken_codes = list(set(broken_codes).intersection(lang_codes))
if broken_codes:
logging.warning("Found %d errors while compiling in codes %s. Mailing admins report now." % (len(broken_codes), ', '.join(broken_codes)))
subject = "Error while compiling po files"
commands = "\n".join(["python manage.py compilemessages -l %s" % lc for lc in broken_codes])
message = """The following codes had errors when compiling their po files: %s.
Please rerun the following commands to see specific line numbers
that need to be corrected on CrowdIn, before we can update the language packs.
%s""" % (
', '.join([lcode_to_ietf(lc) for lc in broken_codes]),
commands,
)
if not settings.DEBUG:
mail_admins(subject=subject, message=message)
logging.info("Report sent.")
else:
logging.info("DEBUG is True so not sending email, but would have sent the following: SUBJECT: %s; MESSAGE: %s" % (subject, message))
return broken_codes
示例8: get_language_pack
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def get_language_pack(lang_code, software_version, callback):
"""Download language pack for specified language"""
lang_code = lcode_to_ietf(lang_code)
logging.info("Retrieving language pack: %s" % lang_code)
request_url = get_language_pack_url(lang_code, software_version)
path, response = download_file(request_url, callback=callback_percent_proxy(callback))
return path
示例9: run_makemessages
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def run_makemessages():
"""Run makemessages command for english po files"""
logging.info("Executing makemessages command")
# Generate english po file
ignore_pattern = ['python-packages/*'] + ['kalite/%s/*' % dirname for dirname in ['central', 'contact', 'faq', 'registration', 'tests', 'stats']]
call_command('makemessages', locale='en', ignore_patterns=ignore_pattern, no_obsolete=True)
# Generate english po file for javascript
ignore_pattern = ['kalite/static/admin/js/*', 'python-packages/*', 'kalite/static/js/i18n/*', 'kalite/static/js/khan-exercises/*']
call_command('makemessages', domain='djangojs', locale='en', ignore_patterns=ignore_pattern, no_obsolete=True)
示例10: update_templates
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def update_templates():
"""Update template po files"""
pot_path = os.path.join(settings.DATA_PATH, "i18n", "pot")
logging.info("Copying english po files to %s" % pot_path)
# post them to exposed URL
ensure_dir(pot_path)
shutil.copy(os.path.join(settings.LOCALE_PATHS[0], "en/LC_MESSAGES/django.po"), os.path.join(pot_path, "kalite.pot"))
shutil.copy(os.path.join(settings.LOCALE_PATHS[0], "en/LC_MESSAGES/djangojs.po"), os.path.join(pot_path, "kalitejs.pot"))
示例11: unpack_language
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def unpack_language(lang_code, zip_filepath=None, zip_fp=None, zip_data=None):
"""Unpack zipped language pack into locale directory"""
lang_code = lcode_to_django_dir(lang_code)
logging.info("Unpacking new translations")
ensure_dir(os.path.join(LOCALE_ROOT, lang_code, "LC_MESSAGES"))
## Unpack into temp dir
z = zipfile.ZipFile(zip_fp or (StringIO(zip_data) if zip_data else open(zip_filepath, "rb")))
z.extractall(os.path.join(LOCALE_ROOT, lang_code))
示例12: cancel_progress
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def cancel_progress(self, stage_status=None, notes=None):
"""
Stamps end time.
"""
logging.info("Cancelling process %s" % (self.process_name))
self.stage_status = stage_status or "cancelled"
self.end_time = datetime.datetime.now()
self.completed=False
self.notes = notes
self.save()
示例13: scrub_locale_paths
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def scrub_locale_paths():
for locale_root in settings.LOCALE_PATHS:
if not os.path.exists(locale_root):
continue
for lang in os.listdir(locale_root):
# Skips if not a directory
if not os.path.isdir(os.path.join(locale_root, lang)):
continue
# If it isn't crowdin/django format, keeeeeeellllllll
if lang != lcode_to_django_dir(lang):
logging.info("Deleting %s directory because it does not fit our language code format standards" % lang)
shutil.rmtree(os.path.join(locale_root, lang))
示例14: cancel_current_stage
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def cancel_current_stage(self, stage_status=None, notes=None):
"""
Delete the current stage--it's reported progress, and contribution to the total # of stages
"""
logging.info("Cancelling stage %s of process %s" % (self.stage_name, self.process_name))
self.stage_percent = 0.
self.update_total_stages(self.total_stages - 1)
self.stage_name = None
self.stage_status = stage_status or "cancelled"
self.notes = notes
self.save()
示例15: run
# 需要导入模块: from kalite.settings import LOG [as 别名]
# 或者: from kalite.settings.LOG import info [as 别名]
def run(self):
jobs = Job.objects.due()
prof_string = "" if not self.do_profile else "[%8.2f MB] " % memory_profiler.memory_usage()[0]
if jobs:
logger.info("%sRunning %d due jobs... (%s)" % (prof_string, jobs.count(), ", ".join(['"%s"' % job.name for job in jobs])))
call_command('cron')
else:
logger.debug("%sNo jobs due to run." % prof_string)
if self.do_gc:
gc.collect()