示例#1
0
def add_translations(locale, i18n_dir, force):
  for domain in domains:
    pot_file = join(i18n_dir, domain+'.pot')
    catalog = create_from_pot(locale, pot_file)
    if catalog:
      write_catalog(catalog, i18n_dir, domain, force)
  print_status('Created catalog for %s' % locale)
示例#2
0
def add_translations(locale, i18n_dir, force):
    for domain in domains:
        pot_file = join(i18n_dir, domain + '.pot')
        catalog = create_from_pot(locale, pot_file)
        if catalog:
            write_catalog(catalog, i18n_dir, domain, force)
    print_status('Created catalog for %s' % locale)
示例#3
0
文件: runserver.py 项目: gmist/f-toy
def runserver_passthru_argv():
  """
  Execute dev_appserver with appropriate parameters. For more details,
  please invoke 'python manage.py runserver --help'.
  """
  from google.appengine.tools import dev_appserver_main
  progname = "manage.py runserver"
  args = []
  args.extend(sys.argv[2:])

  p = get_datastore_paths()
  if not args_have_option(args, "--datastore_path"):
    args.extend(["--datastore_path", p[0]])
  if not args_have_option(args, "--default_partition"):
      args.extend(['--default_partition', ''])
  if not args_have_option(args, "--history_path"):
    args.extend(["--history_path", p[1]])
  # Append the current working directory to the arguments.
  if "-h" in args or "--help" in args:
    render_dict = dev_appserver_main.DEFAULT_ARGS.copy()
    render_dict['script'] = "manage.py runserver"
    print_status(dev_appserver_main.__doc__ % render_dict)
    sys.stdout.flush()
    sys.exit(0)
    
  dev_appserver_main.main([progname] + args + [os.getcwdu()])
示例#4
0
def js_compile():
    args = []
    args.extend(sys.argv[2:])
    os.system('java -jar media/SoyToJsSrcCompiler.jar --shouldProvideRequireSoyNamespaces --cssHandlingScheme GOOG --outputPathFormat media/js/template.soy.js media/soy/tsuhan.soy')
    os.system('java -jar media/closure-stylesheets.jar --output-file media/css/tsuhan_style.css --output-renaming-map media/js/renaming_map.json --output-renaming-map-format JSON --rename CLOSURE media/gss/*.gss media/gss/closure/*.css')
    os.system('java -jar media/closure-stylesheets.jar --output-file media/css/tsuhan_style.css --output-renaming-map media/js/renaming_map.js --output-renaming-map-format CLOSURE_COMPILED --rename CLOSURE media/gss/*.gss media/gss/closure/*.css')
    os.system('python ../closure-library/closure/bin/build/closurebuilder.py --root=../closure-library --root=media -n tsuhan.App -o compiled --output_file=media/js/tsuhan_compile.js -c media/compiler.jar -f "--compilation_level=ADVANCED_OPTIMIZATIONS" -f "--js=media/js/renaming_map.js" -f "--define=goog.DEBUG=false"')
    os.system('python manage.py compile_media')
    print_status('')
示例#5
0
def do_add_translations(target=("t", ""), lang=("l", ""), force=("f", False),
                        i18n_dir=("i", ""), all=("a", False)):
  """
  Add new translations for specified language.
  """
  try:
    locale = Locale.parse(lang)
  except (UnknownLocaleError, ValueError), e:
    print_status("You must specify lang.")
    sys.exit(1)
示例#6
0
文件: __init__.py 项目: IanLewis/kay
def do_wxadmin():
  try:
    import wx
    from mainframe import MainFrame
  except:
    print_status('Can not import wxpython.')
    raise
    
  app = wx.App()
  MainFrame(None, -1, 'Kay WxAdmin')
  app.MainLoop()
示例#7
0
def do_wxadmin():
    try:
        import wx
        from mainframe import MainFrame
    except:
        print_status('Can not import wxpython.')
        raise

    app = wx.App()
    MainFrame(None, -1, 'Kay WxAdmin')
    app.MainLoop()
示例#8
0
def do_add_translations(target=("t", ""),
                        lang=("l", ""),
                        force=("f", False),
                        i18n_dir=("i", ""),
                        all=("a", False)):
    """
  Add new translations for specified language.
  """
    try:
        locale = Locale.parse(lang)
    except (UnknownLocaleError, ValueError), e:
        print_status("You must specify lang.")
        sys.exit(1)
示例#9
0
def write_catalog(catalog, folder, domain, force):
  target = join(folder, str(catalog.locale), 'LC_MESSAGES')
  if not isdir(target):
    makedirs(target)
  filename = join(target, domain+'.po')
  if isfile(filename) and not force:
    print_status("%s already exists, skipped." % filename)
    return
  print_status("Creating %s." % filename)
  f = file(filename, 'w')
  try:
    write_po(f, catalog, width=79)
  finally:
    f.close()
示例#10
0
文件: preparse.py 项目: gmist/kay-ru
def compile_app_templates(app):
  env = app.jinja2_env
  target_dirs = [dir for dir in app.app_settings.TEMPLATE_DIRS\
                   if os.path.isdir(dir)]
  for app in app.app_settings.INSTALLED_APPS:
    #if app.startswith("kay."):
    #  continue
    mod = import_string(app)
    target_dirs.extend(find_template_dir(os.path.dirname(mod.__file__),
                                         ('kay')))
  for dir in target_dirs:
    dest = prepare_destdir(dir)
    print_status("Now compiling templates in %s to %s." % (dir, dest))
    compile_dir(env, dir, dest)
示例#11
0
def write_catalog(catalog, folder, domain, force):
    target = join(folder, str(catalog.locale), 'LC_MESSAGES')
    if not isdir(target):
        makedirs(target)
    filename = join(target, domain + '.po')
    if isfile(filename) and not force:
        print_status("%s already exists, skipped." % filename)
        return
    print_status("Creating %s." % filename)
    f = file(filename, 'w')
    try:
        write_po(f, catalog, width=79)
    finally:
        f.close()
示例#12
0
def compile_app_templates(app):
    env = app.jinja2_env
    target_dirs = [dir for dir in app.app_settings.TEMPLATE_DIRS\
                     if os.path.isdir(dir)]
    for app in app.app_settings.INSTALLED_APPS:
        if app.startswith("kay."):
            continue
        mod = import_string(app)
        target_dirs.extend(
            find_template_dir(os.path.dirname(mod.__file__), ('kay')))
    for dir in target_dirs:
        dest = prepare_destdir(dir)
        print_status("Now compiling templates in %s to %s." % (dir, dest))
        compile_dir(env, dir, dest)
示例#13
0
def prepare_destdir(dir):
  dest = dir.replace("templates", "templates_compiled")
  if path.isdir(dest):
    for d, subdirs, files in os.walk(dest):
      for f in files:
        compiled_filename = "%s/%s" % (d, f)
        orig_filename = compiled_filename.replace("templates_compiled",
                                                  "templates")
        if not path.isfile(orig_filename):
          os.unlink(compiled_filename)
          print_status("%s does not exist. So, '%s' is removed." % (
            orig_filename, compiled_filename))
  else:
    mkdir(dest)
  return dest
示例#14
0
def do_compile_translations(target=("t", ""),
                            i18n_dir=("i", ""),
                            all=("a", False)):
    """
  Compiling all the templates in specified application.
  """
    if not target and not all:
        print_status('Please specify target.')
        sys.exit(1)
    elif target == 'kay':
        print_status('Compiling builtin languages')
        root = path.join(kay.KAY_DIR, 'i18n')
    elif all:
        targets = get_user_apps()
        for target in targets:
            do_compile_translations(target=target, i18n_dir=None, all=False)
        do_compile_translations(target=kay.PROJECT_DIR,
                                i18n_dir=None,
                                all=False)
        sys.exit(0)
    else:
        if i18n_dir:
            root = i18n_dir
        else:
            root = path.join(target, 'i18n')
        if not path.isdir(root):
            print('i18n folder missing')
            sys.exit(1)
        print_status('Compiling %s' % root)

    for domain in domains:
        for lang in listdir(root):
            folder = path.join(root, lang)
            translations = path.join(folder, 'LC_MESSAGES', domain + '.po')

            if path.isfile(translations):
                mo_file = open(translations.replace('.po', '.mo'), 'wb')
                print_status('Compiling %s ' % translations)
                f = file(translations)
                try:
                    catalog = read_po(f, locale=lang)
                finally:
                    f.close()
                # Write standard catalog
                write_mo(mo_file, catalog)
                mo_file.close()
    print_status('All done.')
示例#15
0
def do_bulkloader_passthru_argv():
    """
  Execute bulkloader script with appropriate parameters. For more
  details, please invoke 'python manage.py bulkloader --help'.
  """
    progname = sys.argv[0]
    models = get_all_models_as_dict()
    args = []
    for arg in sys.argv[1:]:
        args.append(arg)
    if '--help' in args:
        print_status(bulkloader.__doc__ % {'arg0': "manage.py bulkloader"})
        sys.stdout.flush()
        sys.stderr.flush()
        sys.exit(0)

    sys.exit(bulkloader.main(args))
示例#16
0
def do_bulkloader_passthru_argv():
  """
  Execute bulkloader script with appropriate parameters. For more
  details, please invoke 'python manage.py bulkloader --help'.
  """
  progname = sys.argv[0]
  models = get_all_models_as_dict()
  args = []
  for arg in sys.argv[1:]:
    args.append(arg)
  if '--help' in args:
    print_status(bulkloader.__doc__ % {'arg0': "manage.py bulkloader"})
    sys.stdout.flush()
    sys.stderr.flush()
    sys.exit(0)
    
  sys.exit(bulkloader.main(args))
示例#17
0
def do_compile_translations(target=("t", ""), i18n_dir=("i", ""),
                            all=("a", False)):
  """
  Compiling all the templates in specified application.
  """
  if not target and not all:
    print_status('Please specify target.')
    sys.exit(1)
  elif target == 'kay':
    print_status('Compiling builtin languages')
    root = path.join(kay.KAY_DIR, 'i18n')
  elif all:
    targets = get_user_apps()
    for target in targets:
      do_compile_translations(target=target, i18n_dir=None, all=False)
    do_compile_translations(target=kay.PROJECT_DIR, i18n_dir=None, all=False)
    sys.exit(0)
  else:
    if i18n_dir:
      root = i18n_dir
    else:
      root = path.join(target, 'i18n')
    if not path.isdir(root):
      print('i18n folder missing')
      sys.exit(1)
    print_status('Compiling %s' % root)

  for domain in domains:
    for lang in listdir(root):
      folder = path.join(root, lang)
      translations = path.join(folder, 'LC_MESSAGES', domain+'.po')

      if path.isfile(translations):
        mo_file = open(translations.replace('.po', '.mo'), 'wb')
        print_status('Compiling %s ' % translations)
        f = file(translations)
        try:
          catalog = read_po(f, locale=lang)
        finally:
          f.close()
        # Write standard catalog
        write_mo(mo_file, catalog)
        mo_file.close()
  print_status('All done.')
示例#18
0
文件: preparse.py 项目: gmist/kay-ru
def prepare_destdir(dir):
  def replace_dirname(orig):
    if 'templates' in orig:
      return orig.replace('templates', 'templates_compiled')
    else:
      return orig+'_compiled'
  dest = replace_dirname(dir)
  if path.isdir(dest):
    for d, subdirs, files in os.walk(dest):
      for f in files:
        compiled_filename = "%s/%s" % (d, f)
        orig_filename = compiled_filename.replace(dest, dir)
        if not path.isfile(orig_filename):
          os.unlink(compiled_filename)
          print_status("%s does not exist. So, '%s' is removed." % (
            orig_filename, compiled_filename))
  else:
    mkdir(dest)
  return dest
示例#19
0
def prepare_destdir(dir):
    def replace_dirname(orig):
        if 'templates' in orig:
            return orig.replace('templates', 'templates_compiled')
        else:
            return orig + '_compiled'

    dest = replace_dirname(dir)
    if path.isdir(dest):
        for d, subdirs, files in os.walk(dest):
            for f in files:
                compiled_filename = "%s/%s" % (d, f)
                orig_filename = compiled_filename.replace(dest, dir)
                if not path.isfile(orig_filename):
                    os.unlink(compiled_filename)
                    print_status("%s does not exist. So, '%s' is removed." %
                                 (orig_filename, compiled_filename))
    else:
        mkdir(dest)
    return dest
示例#20
0
def do_appcfg_passthru_argv():
  """
  Execute appcfg.py with specified parameters. For more details,
  please invoke 'python manage.py appcfg --help'.
  """
  from google.appengine.tools import appcfg
  progname = sys.argv[0]
  if len(sys.argv) < 3:
    sys.stderr.write('action required.\n')
    sys.exit(1)
  if 'update' in sys.argv:
    do_preparse_apps()
  
  models = get_all_models_as_dict()
  args = []
  for arg in sys.argv[2:]:
    args.append(arg)
    if arg == "request_logs":
      args.append(os.getcwdu())

  if "--help" in args or "help" in args or "request_logs" in args:
    args = [progname] + args
  else:
    args = [progname] + args + [os.getcwdu()]
  logging.basicConfig(format=('%(asctime)s %(levelname)s %(filename)s:'
                              '%(lineno)s %(message)s '))
  try:
    app = appcfg.AppCfgApp(args, parser_class=HookedOptionParser)
    result = app.Run()
    if result:
      sys.exit(result)
  except KeyboardInterrupt:
    print_status('Interrupted.')
    sys.exit(1)
  from kay.conf import settings
  if settings.PROFILE and 'update' in sys.argv:
    print_status(
      '--------------------------\n'
      'WARNING: PROFILER ENABLED!\n'
      '--------------------------'
    )
示例#21
0
def do_preparse_apps():
  """
  Pre compile all the jinja2 templates in your applications.
  """
  from kay.conf import LazySettings
  print_status("Compiling templates...")
  application = kay.app.get_application()
  applications = [application]
  settings_treated = []
  for key, settings_name in \
        application.app.app_settings.PER_DOMAIN_SETTINGS.iteritems():
    if not settings_name in settings_treated:
      applications.append(kay.app.get_application(
          settings=LazySettings(settings_module=settings_name)))
    settings_treated.append(settings_name)
  for app in applications:
    compile_app_templates(app.app) # pass KayApp instance
    for key, submount_app in app.mounts.iteritems():
      compile_app_templates(submount_app)

  print_status("Finished compiling templates...")
示例#22
0
文件: shell.py 项目: dbordak/pyblog
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
示例#23
0
  def run(self):
    from google.appengine.tools import appcfg
    from kay.management.preparse import do_preparse_apps
    import sys
    old_stdout = sys.stdout
    old_stderr = sys.stderr
    redir = RedirectText(self.win)
    sys.stdout = redir
    sys.stderr = redir

    import time
    do_preparse_apps()
    args = ['manage.py', 'update', os.getcwdu()]

    try:
      app = appcfg.AppCfgApp(args, raw_input_fn=self.ask_username,
                             password_input_fn=self.ask_pass, error_fh=redir)
      result = app.Run()
      if result:
        print_status('Failed Deploying application.')
      else:
        from kay.conf import settings
        if settings.PROFILE and 'update' in sys.argv:
          print_status('--------------------------\n' \
                         'WARNING: PROFILER ENABLED!\n' \
                         '--------------------------')
    except KeyboardInterrupt:
      print_status('Interrupted.')
    sys.stdout = old_stdout
    sys.stderr = old_stderr
    evt = ThreadEndEvent()
    wx.PostEvent(self.win, evt)
示例#24
0
def create_user(user_name=('u', ''), password=('P', ''), is_admin=('A', False),
                appid=('a', ''), host=('h', ''), path=('p', ''), secure=True):
  """ Create new user using remote_api.
  """
  from kay.auth import (
    create_new_user, DuplicateKeyError,
  )
  if not user_name:
    print_status('user_name required')
    sys.exit(1)
  if not password:
    password = getpass.getpass('Please input a password for new user:'******'/remote_api'
  
  remote_api_stub.ConfigureRemoteApi(None, path, auth_func,
                                     host, secure=secure, save_cookies=True)
  remote_api_stub.MaybeInvokeAuthentication()
  try:
    create_new_user(user_name, password, is_admin=is_admin)
    print_status('A new user: %s successfully created.' % user_name)
    sys.exit(0)
  except DuplicateKeyError, e:
    print_status(e)
    sys.exit(1)
示例#25
0
def do_preparse_apps():
    """
  Pre compile all the jinja2 templates in your applications.
  """
    from kay.conf import LazySettings
    print_status("Compiling templates...")
    application = kay.app.get_application()
    applications = [application]
    settings_treated = []
    for key, settings_name in \
          application.app.app_settings.PER_DOMAIN_SETTINGS.iteritems():
        if not settings_name in settings_treated:
            applications.append(
                kay.app.get_application(settings=LazySettings(
                    settings_module=settings_name)))
        settings_treated.append(settings_name)
    for app in applications:
        compile_app_templates(app.app)  # pass KayApp instance
        for key, submount_app in app.mounts.iteritems():
            if isinstance(submount_app, kay.app.KayApp):
                compile_app_templates(submount_app)

    print_status("Finished compiling templates...")
示例#26
0
def runserver_passthru_argv():
    """
  Execute dev_appserver with appropriate parameters. For more details,
  please invoke 'python manage.py runserver --help'.
  """
    from google.appengine.tools import dev_appserver_main
    progname = "manage.py runserver"
    args = []
    args.extend(sys.argv[2:])

    p = get_datastore_paths()
    if not args_have_option(args, "--datastore_path"):
        args.extend(["--datastore_path", p[0]])
    if not args_have_option(args, "--history_path"):
        args.extend(["--history_path", p[1]])
    # Append the current working directory to the arguments.
    if "-h" in args or "--help" in args:
        render_dict = dev_appserver_main.DEFAULT_ARGS.copy()
        render_dict['script'] = "manage.py runserver"
        print_status(dev_appserver_main.__doc__ % render_dict)
        sys.stdout.flush()
        sys.exit(0)
    dev_appserver_main.main([progname] + args + [os.getcwdu()])
示例#27
0
文件: preparse.py 项目: gmist/kay-ru
def do_preparse_bundle():
  """
  Pre compile all the jinja2 templates in Kay itself.
  """
  print_status("Compiling bundled templates...")
  app = kay.app.get_application()
  env = app.app.jinja2_env
  for dir in find_template_dir(kay.KAY_DIR, ('debug','app_template')):
    dest = prepare_destdir(dir)
    print_status("Now compiling templates in %s to %s." % (dir, dest))
    compile_dir(env, dir, dest)
  print_status("Finished compiling bundled templates...")
示例#28
0
def do_preparse_bundle():
    """
  Pre compile all the jinja2 templates in Kay itself.
  """
    print_status("Compiling bundled templates...")
    app = kay.app.get_application()
    env = app.app.jinja2_env
    for dir in find_template_dir(kay.KAY_DIR, ('debug', 'app_template')):
        dest = prepare_destdir(dir)
        print_status("Now compiling templates in %s to %s." % (dir, dest))
        compile_dir(env, dir, dest)
    print_status("Finished compiling bundled templates...")
示例#29
0
文件: startapp.py 项目: IanLewis/kay
  path_old = os.path.join(kay.PROJECT_DIR, 'app.yaml')
  path_new = os.path.join(top_dir, 'app.yaml')
  fp_old = open(path_old, 'r')
  fp_new = open(path_new, 'w')
  fp_new.write(fp_old.read().replace('%PROJ_NAME%', proj_name))
  fp_old.close()
  fp_new.close()
  try:
    shutil.copymode(path_old, path_new)
    _make_writeable(path_new)
  except OSError:
    sys.stderr.write(style.NOTICE("Notice: Couldn't set permission bits "
                                  "on %s. You're probably using an "
                                  "uncommon filesystem setup. No "
                                  "problem.\n" % path_new))
  print_status("Finished creating new project: %s." % proj_name)
  
  

def startapp(app_name=''):
  """
  Start new application.
  """
  if not app_name:
    sys.stderr.write("app_name required.\n")
    sys.exit(1)
  try:
    __import__(app_name)
  except ImportError:
    pass
  else:
示例#30
0
def do_extract_messages(target=('t', ''),
                        domain=('d', 'messages'),
                        i18n_dir=('i', ''),
                        all=('a', False)):
    """
  Extract messages and create pot file.
  """
    if not domain in ('messages', 'jsmessages'):
        print_status('invalid domain.')
        sys.exit(1)
    if not target and not all:
        print_status('Please specify target.')
        sys.exit(1)
    elif target == 'kay':
        print_status('Extracting core strings')
        root = kay.KAY_DIR
    elif all:
        targets = get_user_apps()
        for target in targets:
            do_extract_messages(target=target,
                                domain=domain,
                                i18n_dir=None,
                                all=False)
        for template_dir in settings.TEMPLATE_DIRS:
            do_extract_messages(target=template_dir,
                                domain=domain,
                                i18n_dir=settings.I18N_DIR,
                                all=False)
        sys.exit(0)
    else:
        root = path.abspath(target)
        if not path.isdir(root):
            print_status('source folder missing')
            sys.exit(1)
        print_status('Extracting from %s' % root)
    if domain == 'messages':
        methods = METHODS
    else:
        methods = JSMETHODS

    catalog = Catalog(msgid_bugs_address=BUGS_ADDRESS,
                      copyright_holder=COPYRIGHT,
                      charset='utf-8')

    def callback(filename, method, options):
        if method != 'ignore':
            print_status(strip_path(filename, root))

    option = {}
    option['extensions'] = ','.join(settings.JINJA2_EXTENSIONS)
    option.update(settings.JINJA2_ENVIRONMENT_KWARGS)
    options = {
        '**/templates/**.*': option,
        '**.html': option,
    }
    extracted = extract_from_dir(root,
                                 methods,
                                 options,
                                 KEYWORDS,
                                 COMMENT_TAGS,
                                 callback=callback,
                                 strip_comment_tags=True)

    for filename, lineno, message, comments in extracted:
        catalog.add(message,
                    None, [(strip_path(filename, root), lineno)],
                    auto_comments=comments)
    if not i18n_dir:
        i18n_dir = path.join(root, 'i18n')
    if not path.isdir(i18n_dir):
        makedirs(i18n_dir)

    f = file(path.join(i18n_dir, domain + '.pot'), 'w')
    try:
        write_po(f, catalog, width=79)
    finally:
        f.close()

    print_status('All done.')
示例#31
0
def do_update_translations(target=("t", ""),
                           lang=("l", ""),
                           statistics=("s", False),
                           i18n_dir=("i", ""),
                           all=("a", False)):
    """
  Update existing translations with updated pot files.
  """
    if not target and not all:
        print_status('Please specify target.')
        sys.exit(1)
    elif target == 'kay':
        print_status('Updating core strings')
        root = path.join(kay.KAY_DIR, 'i18n')
    elif all:
        targets = get_user_apps()
        for target in targets:
            do_update_translations(target=target,
                                   lang=lang,
                                   statistics=statistics,
                                   i18n_dir=None,
                                   all=False)
        do_update_translations(target=kay.PROJECT_DIR,
                               lang=lang,
                               statistics=statistics,
                               i18n_dir=None,
                               all=False)
        sys.exit(0)
    else:
        if i18n_dir:
            root = i18n_dir
        else:
            root = path.join(target, 'i18n')
        if not path.isdir(root):
            print_status('source folder missing')
            sys.exit(1)
        print_status('Updating %s' % root)

    for domain in domains:
        if lang:
            filepath = path.join(root, lang, 'LC_MESSAGES', domain + '.po')
            if not path.exists(filepath):
                print_status("%s not found, skipped." % filepath)
                continue
        try:
            f = file(path.join(root, domain + '.pot'))
        except IOError:
            print_status('Can not open file: %s, skipped.' %
                         path.join(root, domain + '.pot'))
            continue
        try:
            template = read_po(f)
        finally:
            f.close()

        po_files = []
        for lang_dir in listdir(root):
            filename = path.join(root, lang_dir, 'LC_MESSAGES', domain + '.po')
            if lang and filename != \
                               path.join(root, lang, 'LC_MESSAGES', domain+'.po'):
                continue
            if path.exists(filename):
                print_status('Updating %s' % filename, nl=False)
                locale = Locale.parse(lang_dir)
                f = file(filename)
                try:
                    catalog = read_po(f, locale=locale, domain=domain)
                finally:
                    f.close()
                catalog.update(template)

                # XXX: this is kinda dangerous, but as we are using a
                # revision control system anyways that shouldn't make
                # too many problems
                f = file(filename, 'w')
                try:
                    write_po(f,
                             catalog,
                             ignore_obsolete=True,
                             include_previous=False,
                             width=79)
                finally:
                    if statistics:
                        translated = fuzzy = percentage = 0
                        for message in list(catalog)[1:]:
                            if message.string:
                                translated += 1
                            if 'fuzzy' in message.flags:
                                fuzzy += 1
                        if len(catalog):
                            percentage = translated * 100 // len(catalog)
                            print_status(
                                "-> %d of %d messages (%d%%) translated" %
                                (translated, len(catalog), percentage),
                                nl=False)
                            if fuzzy:
                                if fuzzy == 1:
                                    print_status("%d of which is fuzzy" %
                                                 fuzzy,
                                                 nl=False)
                                else:
                                    print_status("%d of which are fuzzy" %
                                                 fuzzy,
                                                 nl=False)
                            print_status()
                    else:
                        print_status()
                    f.close()

    print_status('All done.')
示例#32
0
def do_extract_messages(target=('t', ''), domain=('d', 'messages'),
                        i18n_dir=('i', ''), all=('a', False)):
  """
  Extract messages and create pot file.
  """
  if not domain in ('messages', 'jsmessages'):
    print_status('invalid domain.')
    sys.exit(1)
  if not target and not all:
    print_status('Please specify target.')
    sys.exit(1)
  elif target == 'kay':
    print_status('Extracting core strings')
    root = kay.KAY_DIR
  elif all:
    targets = get_user_apps()
    for target in targets:
      do_extract_messages(target=target, domain=domain, i18n_dir=None,
                          all=False)
    sys.exit(0)
  else:
    root = path.abspath(target)
    if not path.isdir(root):
      print_status('source folder missing')
      sys.exit(1)
    print_status('Extracting from %s' % root)
  if domain == 'messages':
    methods = METHODS
  else:
    methods = JSMETHODS

  catalog = Catalog(msgid_bugs_address=BUGS_ADDRESS,
                    copyright_holder=COPYRIGHT, charset='utf-8')

  def callback(filename, method, options):
    if method != 'ignore':
      print_status(strip_path(filename, root))

  option = {}
  option['extensions'] = ','.join(settings.JINJA2_EXTENSIONS)
  option.update(settings.JINJA2_ENVIRONMENT_KWARGS)
  options = {
    '**/templates/**.*': option,
    '**.html': option,
  }
  extracted = extract_from_dir(root, methods, options, KEYWORDS,
                               COMMENT_TAGS, callback=callback,
                               strip_comment_tags=True)

  for filename, lineno, message, comments in extracted:
    catalog.add(message, None, [(strip_path(filename, root), lineno)],
                auto_comments=comments)
  if not i18n_dir:
    i18n_dir = path.join(root, 'i18n')
  if not path.isdir(i18n_dir):
    makedirs(i18n_dir)

  f = file(path.join(i18n_dir, domain+'.pot'), 'w')
  try:
    write_po(f, catalog, width=79)
  finally:
    f.close()

  print_status('All done.')
示例#33
0
 def callback(filename, method, options):
   if method != 'ignore':
     print_status(strip_path(filename, root))
示例#34
0
def do_update_translations(target=("t", ""), lang=("l", ""),
                           statistics=("s", False), i18n_dir=("i", ""),
                           all=("a", False)):
  """
  Update existing translations with updated pot files.
  """
  if not target and not all:
    print_status('Please specify target.')
    sys.exit(1)
  elif target == 'kay':
    print_status('Updating core strings')
    root = path.join(kay.KAY_DIR, 'i18n')
  elif all:
    targets = get_user_apps()
    for target in targets:
      do_update_translations(target=target, lang=lang, statistics=statistics,
                             i18n_dir=None, all=False)
    sys.exit(0)
  else:
    if i18n_dir:
      root = i18n_dir
    else:
      root = path.join(target, 'i18n')
    if not path.isdir(root):
      print_status('source folder missing')
      sys.exit(1)
    print_status('Updating %s' % root)

  for domain in domains:
    if lang:
      filepath = path.join(root, lang, 'LC_MESSAGES', domain+'.po')
      if not path.exists(filepath):
        print_status("%s not found, skipped." % filepath)
        continue
    try:
      f = file(path.join(root, domain+'.pot'))
    except IOError:
      print_status('Can not open file: %s, skipped.' %
                   path.join(root, domain+'.pot'))
      continue
    try:
      template = read_po(f)
    finally:
      f.close()

    po_files = []
    for lang_dir in listdir(root):
      filename = path.join(root, lang_dir, 'LC_MESSAGES', domain+'.po')
      if lang and filename != \
                         path.join(root, lang, 'LC_MESSAGES', domain+'.po'):
        continue
      if path.exists(filename):
        print_status('Updating %s' % filename, nl=False)
        locale = Locale.parse(lang_dir)
        f = file(filename)
        try:
          catalog = read_po(f, locale=locale, domain=domain)
        finally:
          f.close()
        catalog.update(template)

        # XXX: this is kinda dangerous, but as we are using a
        # revision control system anyways that shouldn't make
        # too many problems
        f = file(filename, 'w')
        try:
          write_po(f, catalog, ignore_obsolete=True,
                   include_previous=False, width=79)
        finally:
          if statistics:
            translated = fuzzy = percentage = 0
            for message in list(catalog)[1:]:
              if message.string:
                translated +=1
              if 'fuzzy' in message.flags:
                fuzzy += 1
            if len(catalog):
              percentage = translated * 100 // len(catalog)
              print_status("-> %d of %d messages (%d%%) translated" % (
                translated, len(catalog), percentage), nl=False)
              if fuzzy:
                if fuzzy == 1:
                  print_status("%d of which is fuzzy" % fuzzy, nl=False)
                else:
                  print_status("%d of which are fuzzy" % fuzzy, nl=False)
              print_status()
          else:
            print_status()
          f.close()

  print_status('All done.')
示例#35
0
def create_categories():
  entities = []
  for name in categories:
    entities.append(Category(name=name))
  db.put(entities)
  print_status("Categories are created succesfully.")
示例#36
0
def do_add_translations(target=("t", ""),
                        lang=("l", ""),
                        force=("f", False),
                        i18n_dir=("i", ""),
                        all=("a", False)):
    """
  Add new translations for specified language.
  """
    try:
        locale = Locale.parse(lang)
    except (UnknownLocaleError, ValueError), e:
        print_status("You must specify lang.")
        sys.exit(1)
    if not target and not all:
        print_status("Please specify target.")
        sys.exit(1)
    elif target == 'kay':
        i18n_dir = join(kay.KAY_DIR, 'i18n')
        add_translations(locale, i18n_dir, force)
    elif all:
        targets = get_user_apps()
        for target in targets:
            do_add_translations(target=target,
                                lang=lang,
                                force=force,
                                i18n_dir=None,
                                all=False)
        do_add_translations(target=kay.PROJECT_DIR,
                            lang=lang,
                            force=force,
示例#37
0
def create_competition():
  entities = []
  for item in competitions:
    entities.append(Competition(name=item[0],detail=item[1]))
  db.put(entities)
  print_status("Competitions are created successfully.")
示例#38
0
def create_from_pot(locale, path):
    try:
        f = file(path)
    except IOError, e:
        print_status("Cant open file. Skipped %s." % path)
        return None
示例#39
0
)

domains = ['messages', 'jsmessages']

def do_add_translations(target=("t", ""), lang=("l", ""), force=("f", False),
                        i18n_dir=("i", ""), all=("a", False)):
  """
  Add new translations for specified language.
  """
  try:
    locale = Locale.parse(lang)
  except (UnknownLocaleError, ValueError), e:
    print_status("You must specify lang.")
    sys.exit(1)
  if not target and not all:
    print_status("Please specify target.")
    sys.exit(1)
  elif target == 'kay':
    i18n_dir = join(kay.KAY_DIR, 'i18n')
    add_translations(locale, i18n_dir, force)
  elif all:
    targets = get_user_apps()
    for target in targets:
      do_add_translations(target=target, lang=lang, force=force,
                          i18n_dir=None, all=False)
    sys.exit(0)
  else:
    if not i18n_dir:
      i18n_dir = join(target, 'i18n')
    add_translations(locale, i18n_dir, force)
示例#40
0
def delete_categories():
  db.delete(Category.all().fetch(100))
  print_status("Categories are deleted succesfully.")
示例#41
0
def create_from_pot(locale, path):
  try:
    f = file(path)
  except IOError, e:
    print_status("Cant open file. Skipped %s." % path)
    return None
示例#42
0
    path_new = os.path.join(top_dir, 'app.yaml')
    fp_old = open(path_old, 'r')
    fp_new = open(path_new, 'w')
    fp_new.write(fp_old.read().replace('%PROJ_NAME%', proj_name))
    fp_old.close()
    fp_new.close()
    try:
        shutil.copymode(path_old, path_new)
        _make_writeable(path_new)
    except OSError:
        sys.stderr.write(
            style.NOTICE("Notice: Couldn't set permission bits "
                         "on %s. You're probably using an "
                         "uncommon filesystem setup. No "
                         "problem.\n" % path_new))
    print_status("Finished creating new project: %s." % proj_name)


def startapp(app_name=''):
    """
  Start new application.
  """
    if not app_name:
        sys.stderr.write("app_name required.\n")
        sys.exit(1)
    try:
        __import__(app_name)
    except ImportError:
        pass
    else:
        sys.stderr.write("%r conflicts with the name of an existing Python"
示例#43
0
def dump_or_restore_all(help, data_set_name, app_id, url, directory, op):
    if help:
        print_status('help for %s' % op)
        sys.exit(0)
    if not data_set_name:
        data_set_name = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
    if not app_id:
        app_id = get_appid()
    if not url:
        url = "https://%s.appspot.com/remote_api" % app_id
    if not directory:
        directory = '_backup'
    target_dir = os.path.join(kay.PROJECT_DIR, directory, data_set_name)

    if not os.path.isdir(target_dir):
        if op == DUMP:
            makedirs(target_dir)
            print_status('Directory "%s" created.' % target_dir)
        else:
            print_status('Directory "%s" is missing, exiting...' % target_dir)
            sys.exit(1)

    current_time = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
    models = get_all_models_as_dict(only_polymodel_base=True)
    results = {}
    if op == RESTORE:
        base_args = ["bulkloader", "--restore"]
    else:
        base_args = ["bulkloader", "--dump"]
    if "localhost" in url:
        base_args.append("--app_id=%s" % app_id)
        bulkloader.RequestManager.AuthFunction = dummy_auth_func
    else:
        bulkloader.RequestManager.AuthFunction = real_auth_func
    for key, model in models.iteritems():
        kind = model.kind()
        db_filename = os.path.join(
            target_dir, "bulkloader-%s-%s.progress" % (kind, current_time))
        log_file = os.path.join(target_dir,
                                "bulkloader-%s-%s.log" % (kind, current_time))
        result_db_filename = os.path.join(
            target_dir, "bulkloader-%s-%s.result" % (kind, current_time))
        args = copy.copy(base_args)
        args.append("--filename=%s" %
                    os.path.join(target_dir, "%s.dat" % kind))
        args.append("--kind=%s" % kind)
        args.append("--db_filename=%s" % db_filename)
        args.append("--log_file=%s" % log_file)
        if op == DUMP:
            args.append("--result_db_filename=%s" % result_db_filename)
        args.append("--url=%s" % url)
        try:
            from werkzeug.utils import import_string
            backup_mod = import_string(directory)
            if op == RESTORE:
                args.extend(backup_mod.restore_options[kind])
            else:
                args.extend(backup_mod.dump_options[kind])
        except:
            pass
        try:
            results[key] = bulkloader.main(args)
        except bulkloader.FileNotFoundError, e:
            print_status("File not found, skipped: %s" % e)
            results[key] = -1
            continue
        logging.getLogger('google.appengine.tools.bulkloader').handlers = []
示例#44
0
def delete_competition():
  db.delete(Competition.all().fetch(100))
  print_status("Competitions are deleted successfully.")
示例#45
0
def dump_or_restore_all(help, data_set_name, app_id, url, directory, batch_size, op):
  if help:
    print_status('help for %s' % op)
    sys.exit(0)
  if not data_set_name:
    data_set_name = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
  if not app_id:
    app_id = get_appid()
  if not url:
    url = "https://%s.appspot.com/remote_api" % app_id
  if not directory:
    directory = '_backup'
  target_dir = os.path.join(kay.PROJECT_DIR, directory, data_set_name)

  if not os.path.isdir(target_dir):
    if op == DUMP:
      makedirs(target_dir)
      print_status('Directory "%s" created.' % target_dir)
    else:
      print_status('Directory "%s" is missing, exiting...' % target_dir)
      sys.exit(1)
      
  current_time = datetime.datetime.now().strftime("%Y%m%d.%H%M%S")
  models = get_all_models_as_dict(only_polymodel_base=True)
  results = {}
  if op == RESTORE:
    base_args = ["bulkloader", "--restore"]
  else:
    base_args = ["bulkloader", "--dump"] 
  base_args.append("--application=%s" % app_id)
  if "localhost" in url:
    bulkloader.RequestManager.AuthFunction = dummy_auth_func
  else:
    bulkloader.RequestManager.AuthFunction = real_auth_func
  for key, model in models.iteritems():
    kind = model.kind()
    db_filename = os.path.join(target_dir, "bulkloader-%s-%s.progress" %
                               (kind, current_time))
    log_file = os.path.join(target_dir, "bulkloader-%s-%s.log" %
                            (kind, current_time))
    result_db_filename = os.path.join(target_dir, "bulkloader-%s-%s.result" %
                                      (kind, current_time))
    args = copy.copy(base_args)
    args.append("--filename=%s" % os.path.join(target_dir, "%s.dat" % kind))
    args.append("--kind=%s" % kind)
    args.append("--db_filename=%s" % db_filename)
    args.append("--log_file=%s" % log_file)
    if batch_size:
        args.append("--batch_size=%s" % int(batch_size))
    if op == DUMP:
      args.append("--result_db_filename=%s" % result_db_filename)
    args.append("--url=%s" % url)
    try:
      from werkzeug.utils import import_string
      backup_mod = import_string(directory)
      if op == RESTORE:
        args.extend(backup_mod.restore_options[kind])
      else:
        args.extend(backup_mod.dump_options[kind])
    except:
      pass
    try:
      results[key] = bulkloader.main(args)
    except bulkloader.FileNotFoundError, e:
      print_status("File not found, skipped: %s" % e)
      results[key] = -1
      continue
    logging.getLogger('google.appengine.tools.bulkloader').handlers = []
示例#46
0
 def callback(filename, method, options):
     if method != 'ignore':
         print_status(strip_path(filename, root))