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)
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)
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 _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