本文整理汇总了Python中txclib.log.logger.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getset_host_credentials
def getset_host_credentials(self, host, user=None, password=None):
"""
Read .transifexrc and report user,pass for a specific host else ask the
user for input.
"""
try:
username = self.txrc.get(host, 'username')
passwd = self.txrc.get(host, 'password')
except (configparser.NoOptionError, configparser.NoSectionError):
logger.info("No entry found for host %s. Creating..." % host)
username = user or input("Please enter your transifex username: ")
while (not username):
username = input("Please enter your transifex username: ")
passwd = password
while (not passwd):
passwd = getpass.getpass()
logger.info("Updating %s file..." % self.txrc_file)
self.txrc.add_section(host)
self.txrc.set(host, 'username', username)
self.txrc.set(host, 'password', passwd)
self.txrc.set(host, 'token', '')
self.txrc.set(host, 'hostname', host)
return username, passwd
示例2: cmd_pull
def cmd_pull(argv, path_to_tx):
"Pull files from remote server to local repository"
parser = pull_parser()
(options, args) = parser.parse_args(argv)
if options.fetchall and options.languages:
parser.error("You can't user a language filter along with the"\
" -a|--all option")
languages = parse_csv_option(options.languages)
resources = parse_csv_option(options.resources)
pseudo = options.pseudo
skip = options.skip_errors
minimum_perc = options.minimum_perc or None
try:
_go_to_dir(path_to_tx)
except UnInitializedError as e:
utils.logger.error(e)
return
# instantiate the project.Project
prj = project.Project(path_to_tx)
prj.pull(
languages=languages, resources=resources, overwrite=options.overwrite,
fetchall=options.fetchall, fetchsource=options.fetchsource,
force=options.force, skip=skip, minimum_perc=minimum_perc,
mode=options.mode, pseudo=pseudo
)
logger.info("Done.")
示例3: cmd_pull
def cmd_pull(argv, path_to_tx):
"""Pull files from remote server to local repository"""
parser = pull_parser()
options = parser.parse_args(argv)
if options.fetchall and options.languages:
parser.error("You can't user a language filter along with the "
"-a|--all option")
languages = parse_csv_option(options.languages)
resources = parse_csv_option(options.resources)
pseudo = options.pseudo
# Should we download as xliff?
xliff = options.xliff
parallel = options.parallel
skip = options.skip_errors
minimum_perc = options.minimum_perc or None
_go_to_dir(path_to_tx)
# instantiate the project.Project
prj = project.Project(path_to_tx)
branch = get_branch_from_options(options, prj.root)
prj.pull(
languages=languages, resources=resources, overwrite=options.overwrite,
fetchall=options.fetchall, fetchsource=options.fetchsource,
force=options.force, skip=skip, minimum_perc=minimum_perc,
mode=options.mode, pseudo=pseudo, xliff=xliff, branch=branch,
parallel=parallel, no_interactive=options.no_interactive,
)
logger.info("Done.")
示例4: cmd_status
def cmd_status(argv, path_to_tx):
"Print status of current project"
parser = status_parser()
(options, args) = parser.parse_args(argv)
resources = parse_csv_option(options.resources)
prj = project.Project(path_to_tx)
resources = prj.get_chosen_resources(resources)
resources_num = len(resources)
for idx, res in enumerate(resources):
p, r = res.split('.')
logger.info("%s -> %s (%s of %s)" % (p, r, idx + 1, resources_num))
logger.info("Translation Files:")
slang = prj.get_resource_option(res, 'source_lang')
sfile = prj.get_resource_option(res, 'source_file') or "N/A"
lang_map = prj.get_resource_lang_mapping(res)
logger.info(" - %s: %s (%s)" % (utils.color_text(slang, "RED"),
sfile, utils.color_text("source", "YELLOW")))
files = prj.get_resource_files(res)
fkeys = files.keys()
fkeys.sort()
for lang in fkeys:
local_lang = lang
if lang in lang_map.values():
local_lang = lang_map.flip[lang]
logger.info(" - %s: %s" % (utils.color_text(local_lang, "RED"),
files[lang]))
logger.info("")
示例5: _delete_translations
def _delete_translations(self, project_details,
resource, stats, languages):
"""Delete the specified translations for the specified resource."""
logger.info("Deleting translations from resource %s:" % resource)
for language in languages:
self._delete_translation(
project_details, resource, stats, language
)
示例6: cmd_init
def cmd_init(argv, path_to_tx):
"Initialize a new transifex project."
parser = init_parser()
(options, args) = parser.parse_args(argv)
if len(args) > 1:
parser.error("Too many arguments were provided. Aborting...")
if args:
path_to_tx = args[0]
else:
path_to_tx = os.getcwd()
if os.path.isdir(os.path.join(path_to_tx,".tx")):
logger.info("tx: There is already a tx folder!")
reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
while (reinit != 'y' and reinit != 'Y' and reinit != 'N' and reinit != 'n' and reinit != ''):
reinit = raw_input("Do you want to delete it and reinit the project? [y/N]: ")
if not reinit or reinit in ['N', 'n', 'NO', 'no', 'No']:
return
# Clean the old settings
# FIXME: take a backup
else:
rm_dir = os.path.join(path_to_tx, ".tx")
shutil.rmtree(rm_dir)
logger.info("Creating .tx folder...")
os.mkdir(os.path.join(path_to_tx,".tx"))
# Handle the credentials through transifexrc
home = os.path.expanduser("~")
txrc = os.path.join(home, ".transifexrc")
config = OrderedRawConfigParser()
default_transifex = "https://www.transifex.net"
transifex_host = options.host or raw_input("Transifex instance [%s]: " % default_transifex)
if not transifex_host:
transifex_host = default_transifex
if not transifex_host.startswith(('http://', 'https://')):
transifex_host = 'https://' + transifex_host
config_file = os.path.join(path_to_tx, ".tx", "config")
if not os.path.exists(config_file):
# The path to the config file (.tx/config)
logger.info("Creating skeleton...")
config = OrderedRawConfigParser()
config.add_section('main')
config.set('main', 'host', transifex_host)
# Touch the file if it doesn't exist
logger.info("Creating config file...")
fh = open(config_file, 'w')
config.write(fh)
fh.close()
prj = project.Project(path_to_tx)
prj.getset_host_credentials(transifex_host, user=options.user,
password=options.password)
prj.save()
logger.info("Done.")
示例7: modify_expr
def modify_expr():
"""Modify the file filter of a resource."""
prj = project.Project(path_to_tx)
res_id = request.form['res_id']
expr = request.form['value']
logger.info("Changing expression of %s to %s" % (res_id, expr))
prj.config.set("%s" % res_id, "file_filter", expr)
prj.save()
return expr
示例8: pull
def pull():
resourceLink = request.form["resources"]
resources = resourceLink.split("*//")
prj = project.Project(path_to_tx)
#resource = request.args.get('resource')
logger.info(resources[-1])
#prj.pull(resources=[resource], fetchall=True, skip=True)
return jsonify(result="OK")
示例9: push
def push():
resourceLink = request.form["resources"]
resources = resourceLink.split("*//")
logger.info("zaab")
prj = project.Project(path_to_tx)
try:
prj.push(resources=resources, source=True)
prj.push(resources=resources, skip=True, translations=True, source=False)
return "success"
except:
return "failed"
示例10: cmd_delete
def cmd_delete(argv, path_to_tx):
"Delete an accessible resource or translation in a remote server."
parser = delete_parser()
(options, args) = parser.parse_args(argv)
languages = parse_csv_option(options.languages)
resources = parse_csv_option(options.resources)
skip = options.skip_errors
force = options.force_delete
prj = project.Project(path_to_tx)
prj.delete(resources, languages, skip, force)
logger.info("Done.")
示例11: cmd_init
def cmd_init(argv, path_to_tx):
"""Initialize a new Transifex project."""
parser = init_parser()
options = parser.parse_args(argv)
path_to_tx = options.path_to_tx or os.getcwd()
print(messages.init_intro)
save = options.save
# if we already have a config file and we are not told to override it
# in the args we have to ask
config_file = os.path.join(path_to_tx, ".tx", "config")
if os.path.isfile(config_file):
if not save:
if options.no_interactive:
parser.error("Project already initialized.")
logger.info(messages.init_initialized)
if not utils.confirm(messages.init_reinit):
return
os.remove(config_file)
if not os.path.isdir(os.path.join(path_to_tx, ".tx")):
logger.info("Creating .tx folder...")
os.mkdir(os.path.join(path_to_tx, ".tx"))
default_transifex = "https://www.transifex.com"
transifex_host = options.host or default_transifex
if not transifex_host.startswith(('http://', 'https://')):
transifex_host = 'https://' + transifex_host
if not os.path.exists(config_file):
# Handle the credentials through transifexrc
config = OrderedRawConfigParser()
config.add_section('main')
config.set('main', 'host', transifex_host)
# Touch the file if it doesn't exist
logger.info("Creating config file...")
fh = open(config_file, 'w')
config.write(fh)
fh.close()
if not options.skipsetup and not options.no_interactive:
logger.info(messages.running_tx_set)
cmd_config([], path_to_tx)
else:
prj = project.Project(path_to_tx)
prj.getset_host_credentials(transifex_host, username=options.user,
password=options.password,
token=options.token, force=options.save,
no_interactive=options.no_interactive)
prj.save()
logger.info("Done.")
示例12: _set_source_file
def _set_source_file(path_to_tx, resource, lang, path_to_file):
"""Reusable method to set source file."""
proj, res = resource.split('.')
if not proj or not res:
raise Exception("\"%s.%s\" is not a valid resource identifier. "
"It should be in the following format "
"project_slug.resource_slug." %
(proj, res))
if not lang:
raise Exception("You haven't specified a source language.")
try:
_go_to_dir(path_to_tx)
except UnInitializedError as e:
utils.logger.error(e)
return
if not os.path.exists(path_to_file):
raise Exception("tx: File ( %s ) does not exist." %
os.path.join(path_to_tx, path_to_file))
# instantiate the project.Project
prj = project.Project(path_to_tx)
root_dir = os.path.abspath(path_to_tx)
if root_dir not in os.path.normpath(os.path.abspath(path_to_file)):
raise Exception("File must be under the project root directory.")
logger.info("Setting source file for resource %s.%s ( %s -> %s )." % (
proj, res, lang, path_to_file))
path_to_file = os.path.relpath(path_to_file, root_dir)
prj = project.Project(path_to_tx)
# FIXME: Check also if the path to source file already exists.
try:
try:
prj.config.get("%s.%s" % (proj, res), "source_file")
except configparser.NoSectionError:
prj.config.add_section("%s.%s" % (proj, res))
except configparser.NoOptionError:
pass
finally:
prj.config.set(
"%s.%s" % (proj, res), "source_file", posix_path(path_to_file)
)
prj.config.set("%s.%s" % (proj, res), "source_lang", lang)
prj.save()
示例13: cmd_help
def cmd_help(argv, path_to_tx):
"""List all available commands"""
parser = help_parser()
(options, args) = parser.parse_args(argv)
if len(args) > 1:
parser.error("Multiple arguments received. Exiting...")
# Get all commands
fns = utils.discover_commands()
# Print help for specific command
if len(args) == 1:
try:
fns[argv[0]](['--help'], path_to_tx)
except KeyError:
utils.logger.error("Command %s not found" % argv[0])
# or print summary of all commands
# the code below will only be executed if the KeyError exception is thrown
# becuase in all other cases the function called with --help will exit
# instead of return here
keys = fns.keys()
keys.sort()
logger.info("Transifex command line client.\n")
logger.info("Available commands are:")
for key in keys:
logger.info(" %-15s\t%s" % (key, fns[key].func_doc))
logger.info("\nFor more information run %s command --help" % sys.argv[0])
示例14: pullResource
def pullResource():
#pull for particular resource and particular languages of that resource
#languages are in one string and we split them by *// also at the end of that string we have the resource name
resourceLanguages = request.form["resourceLanguages"]
languages = resourceLanguages.split("*//")
resource = languages[-1]
logger.info("shit")
languages.pop()
prj = project.Project(path_to_tx)
try:
prj.pull(resources=[resource], fetchall=True, skip=True, languages=languages)
return "success"
except:
return "failed"
示例15: _get_transifex_file
def _get_transifex_file(self, directory=None):
"""Fetch the path of the .transifexrc file.
It is in the home directory ofthe user by default.
"""
if directory is None:
directory = os.path.expanduser('~')
txrc_file = os.path.join(directory, ".transifexrc")
logger.debug(".transifexrc file is at %s" % directory)
if not os.path.exists(txrc_file):
msg = "No authentication data found."
logger.info(msg)
mask = os.umask(077)
open(txrc_file, 'w').close()
os.umask(mask)
return txrc_file