def _init(self, path_to_tx=None): # The path to the root of the project, where .tx lives! self.root = path_to_tx or find_dot_tx() logger.debug("Path to tx is %s." % self.root) if not self.root: MSG("Cannot find any .tx directory!") MSG("Run 'tx init' to initialize your project first!") raise ProjectNotInit() # The path to the config file (.tx/config) self.config_file = os.path.join(self.root, ".tx", "config") logger.debug("Config file is %s" % self.config_file) # Touch the file if it doesn't exist if not os.path.exists(self.config_file): MSG("Cannot find the config file (.tx/config)!") MSG("Run 'tx init' to fix this!") raise ProjectNotInit() # The dictionary which holds the config parameters after deser/tion. # Read the config in memory self.config = OrderedRawConfigParser() try: self.config.read(self.config_file) except Exception, err: MSG("WARNING: Cannot open/parse .tx/config file", err) MSG("Run 'tx init' to fix this!") raise ProjectNotInit()
def _get_transifex_config(self, txrc_files): """Read the configuration from the .transifexrc files.""" txrc = OrderedRawConfigParser() try: txrc.read(txrc_files) except Exception, e: msg = "Cannot read configuration file: %s" % e raise ProjectNotInit(msg)
def _read_config_file(self, config_file): """Parse the config file and return its contents.""" config = OrderedRawConfigParser() try: config.read(config_file) except Exception, err: msg = "Cannot open/parse .tx/config file: %s" % err raise ProjectNotInit(msg)
def _get_transifex_config(self, txrc_file): """Read the configuration from the .transifexrc file.""" txrc = OrderedRawConfigParser() try: txrc.read(txrc_file) except Exception, e: msg = "Cannot read global configuration file: %s" % e raise ProjectNotInit(msg)
class Project(object): """ Represents an association between the local and remote project instances. """ def __init__(self, path_to_tx=None, init=True): """ Initialize the Project attributes. """ if init: self._init(path_to_tx) def _init(self, path_to_tx=None): # The path to the root of the project, where .tx lives! self.root = path_to_tx or find_dot_tx() logger.debug("Path to tx is %s." % self.root) if not self.root: MSG("Cannot find any .tx directory!") MSG("Run 'tx init' to initialize your project first!") raise ProjectNotInit() # The path to the config file (.tx/config) self.config_file = os.path.join(self.root, ".tx", "config") logger.debug("Config file is %s" % self.config_file) # Touch the file if it doesn't exist if not os.path.exists(self.config_file): MSG("Cannot find the config file (.tx/config)!") MSG("Run 'tx init' to fix this!") raise ProjectNotInit() # The dictionary which holds the config parameters after deser/tion. # Read the config in memory self.config = OrderedRawConfigParser() try: self.config.read(self.config_file) except Exception, err: MSG("WARNING: Cannot open/parse .tx/config file", err) MSG("Run 'tx init' to fix this!") raise ProjectNotInit() home = os.path.expanduser("~") self.txrc_file = os.path.join(home, ".transifexrc") logger.debug(".transifexrc file is at %s" % home) if not os.path.exists(self.txrc_file): MSG("No configuration file found.") # Writing global configuration file mask = os.umask(077) open(self.txrc_file, 'w').close() os.umask(mask) self.txrc = OrderedRawConfigParser() try: self.txrc.read(self.txrc_file) except Exception, err: MSG("WARNING: Cannot global conf file (%s)" % err) MSG("Run 'tx init' to fix this!") raise ProjectNotInit()
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.com" 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.")
def _get_transifex_config(self, txrc_files): """Read the configuration from the .transifexrc files.""" txrc = OrderedRawConfigParser() try: txrc.read(txrc_files) except Exception as e: msg = "Cannot read configuration file: %s" % e raise ProjectNotInit(msg) self._migrate_txrc_file(txrc) return txrc
def get_transifex_config(txrc_file): """Read the configuration from the .transifexrc files.""" txrc = OrderedRawConfigParser() try: txrc.read((txrc_file, )) except Exception as e: msg = "Cannot read configuration file: %s" % e raise ProjectNotInit(msg) migrate_txrc_file(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() 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.")
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 cmd_init(argv, path_to_tx): "Initialize a new transifex project." # Current working dir path usage="usage: %prog [tx_options] init <path>" description="This command initializes a new project for use with"\ " transifex. It is recommended to execute this command in the"\ " top level directory of your project so that you can include"\ " all files under it in transifex. If no path is provided, the"\ " current working dir will be used." parser = OptionParser(usage=usage, description=description) parser.add_option("--host", action="store", dest="host", default=None, help="Specify a default Transifex host.") parser.add_option("--user", action="store", dest="user", default=None, help="Specify username for Transifex server.") parser.add_option("--pass", action="store", dest="password", default=None, help="Specify password for Transifex server.") (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")): utils.MSG("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) utils.MSG("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) utils.MSG("Creating skeleton...") config = OrderedRawConfigParser() config.add_section('main') config.set('main', 'host', transifex_host) # Touch the file if it doesn't exist utils.MSG("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() utils.MSG("Done.")
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.")
def cmd_init(argv, path_to_tx): "Initialize a new transifex project." # Current working dir path usage = "usage: %prog [tx_options] init <path>" description="This command initializes a new project for use with"\ " transifex. It is recommended to execute this command in the"\ " top level directory of your project so that you can include"\ " all files under it in transifex. If no path is provided, the"\ " current working dir will be used." parser = OptionParser(usage=usage, description=description) parser.add_option("--host", action="store", dest="host", default=None, help="Specify a default Transifex host.") parser.add_option("--user", action="store", dest="user", default=None, help="Specify username for Transifex server.") parser.add_option("--pass", action="store", dest="password", default=None, help="Specify password for Transifex server.") (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")): utils.MSG("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) utils.MSG("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) utils.MSG("Creating skeleton...") config = OrderedRawConfigParser() config.add_section('main') config.set('main', 'host', transifex_host) # Touch the file if it doesn't exist utils.MSG("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() utils.MSG("Done.")