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.")
def _migrate_txrc_file(self, txrc): """Migrate the txrc file, if needed.""" if not os.path.exists(self.txrc_file): return txrc for section in txrc.sections(): orig_hostname = txrc.get(section, 'hostname') hostname = visit_hostname(orig_hostname) if hostname != orig_hostname: msg = "Hostname %s should be changed to %s." logger.info(msg % (orig_hostname, hostname)) if (sys.stdin.isatty() and sys.stdout.isatty() and utils.confirm('Change it now? ', default=True)): txrc.set(section, 'hostname', hostname) msg = 'Hostname changed' logger.info(msg) else: hostname = orig_hostname self._save_txrc_file(txrc) return txrc
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() 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 if os.path.isdir(os.path.join(path_to_tx, ".tx")) and not save: logger.info("tx: There is already a tx folder!") if not utils.confirm( prompt='Do you want to delete it and reinit the project?', default=False): return # Clean the old settings # FIXME: take a backup else: save = True 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")) default_transifex = "https://www.transifex.com" transifex_host = options.host or 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...") # 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() prj = project.Project(path_to_tx) prj.getset_host_credentials(transifex_host, username=options.user, password=options.password, token=options.token, save=save) prj.save() logger.info("Done.")