示例#1
0
    def _init(self, path_to_tx=None):
        instructions = "Run 'tx init' to initialize your project first!"
        try:
            self.root = self._get_tx_dir_path(path_to_tx)
            self.config_file = self._get_config_file_path(self.root)
            self.config = self._read_config_file(self.config_file)

            local_txrc_file = self._get_transifex_file(os.getcwd())
            if os.path.exists(local_txrc_file):
                self.txrc_file = local_txrc_file
            else:
                self.txrc_file = self._get_transifex_file()
            self.txrc = self._get_transifex_config([self.txrc_file, ])
        except ProjectNotInit as e:
            logger.error('\n'.join([six.u(str(e)), instructions]))
            raise
        host = self.config.get('main', 'host')
        if host.lower().startswith('https://'):
            self.conn = urllib3.connection_from_url(
                host,
                cert_reqs=ssl.CERT_REQUIRED,
                ca_certs=certs_file()
            )
        else:
            self.conn = urllib3.connection_from_url(host)
示例#2
0
 def _get_stats_for_resource(self):
     """Get the statistics information for a resource."""
     try:
         r, charset = self.do_url_request('resource_stats')
         logger.debug("Statistics response is %s" % r)
         stats = parse_json(r)
     except HttpNotFound:
         logger.debug("Resource not found, creating...")
         stats = {}
     except Exception as e:
         logger.debug(six.u(str(e)))
         raise
     return stats
示例#3
0
 def _get_stats_for_resource(self):
     """Get the statistics information for a resource."""
     try:
         r, charset = self.do_url_request('resource_stats')
         logger.debug("Statistics response is %s" % r)
         stats = parse_json(r)
     except HttpNotFound:
         logger.debug("Resource not found, creating...")
         stats = {}
     except Exception as e:
         logger.debug(six.u(str(e)))
         raise
     return stats
示例#4
0
def get_details(api_call, username, password, *args, **kwargs):
    """
    Get the tx project info through the API.

    This function can also be used to check the existence of a project.
    """
    url = API_URLS[api_call] % kwargs
    try:
        data, charset = make_request('GET', kwargs['hostname'], url, username, password)
        return parse_json(data)
    except Exception as e:
        logger.debug(six.u(str(e)))
        raise
示例#5
0
def get_details(api_call, username, password, *args, **kwargs):
    """
    Get the tx project info through the API.

    This function can also be used to check the existence of a project.
    """
    url = API_URLS[api_call] % kwargs
    try:
        data, charset = make_request('GET', kwargs['hostname'], url, username,
                                     password)
        return parse_json(data)
    except Exception as e:
        logger.debug(six.u(str(e)))
        raise
示例#6
0
 def _init(self, path_to_tx=None):
     instructions = "Run 'tx init' to initialize your project first!"
     try:
         self.root = self._get_tx_dir_path(path_to_tx)
         self.config_file = self._get_config_file_path(self.root)
         self.config = self._read_config_file(self.config_file)
         self.txrc_file = self._get_transifex_file()
         local_txrc_file = self._get_transifex_file(os.getcwd())
         self.txrc = self._get_transifex_config(
             [self.txrc_file, local_txrc_file])
         if os.path.exists(local_txrc_file):
             self.txrc_file = local_txrc_file
     except ProjectNotInit as e:
         logger.error('\n'.join([six.u(str(e)), instructions]))
         raise
     host = self.config.get('main', 'host')
     if host.lower().startswith('https://'):
         self.conn = urllib3.connection_from_url(
             host, cert_reqs=ssl.CERT_REQUIRED, ca_certs=certs_file())
     else:
         self.conn = urllib3.connection_from_url(host)