コード例 #1
0
def ensure_local_plotly_files():
    """Ensure that filesystem is setup/filled out in a valid way"""
    if _file_permissions:
        if not os.path.isdir(PLOTLY_DIR):
            os.mkdir(PLOTLY_DIR)
        for fn in [CREDENTIALS_FILE, CONFIG_FILE]:
            contents = utils.load_json_dict(fn)
            for key, val in list(_FILE_CONTENT[fn].items()):
                # TODO: removed type checking below, may want to revisit
                if key not in contents:
                    contents[key] = val
            contents_keys = list(contents.keys())
            for key in contents_keys:
                if key not in _FILE_CONTENT[fn]:
                    del contents[key]
            utils.save_json_dict(fn, contents)
    else:
        warnings.warn(
            "Looks like you don't have 'read-write' permission to "
            "your 'home' ('~') directory or to our '~/.plotly' "
            "directory. That means plotly's python api can't setup "
            "local configuration files. No problem though! You'll "
            "just have to sign-in using 'plotly.plotly.sign_in()'. For help "
            "with that: 'help(plotly.plotly.sign_in)'."
            "\nQuestions? [email protected]")
コード例 #2
0
ファイル: tools.py プロジェクト: shubhabrataroy/python-api
def set_config_file(plotly_domain=None,
                    plotly_streaming_domain=None,
                    plotly_api_domain=None,
                    plotly_ssl_verification=None,
                    plotly_proxy_authorization=None):
    """Set the keyword-value pairs in `~/.plotly/.config`.

    :param (str) plotly_domain: ex - https://plot.ly
    :param (str) plotly_streaming_domain: ex - stream.plot.ly
    :param (str) plotly_api_domain: ex - https://api.plot.ly
    :param (bool) plotly_ssl_verification: True = verify, False = don't verify
    :param (bool) plotly_proxy_authorization: True = use plotly proxy auth creds

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    settings = get_config_file()
    if isinstance(plotly_domain, six.string_types):
        settings['plotly_domain'] = plotly_domain
    if isinstance(plotly_streaming_domain, six.string_types):
        settings['plotly_streaming_domain'] = plotly_streaming_domain
    if isinstance(plotly_api_domain, six.string_types):
        settings['plotly_api_domain'] = plotly_api_domain
    if isinstance(plotly_ssl_verification, (six.string_types, bool)):
        settings['plotly_ssl_verification'] = plotly_ssl_verification
    if isinstance(plotly_proxy_authorization, (six.string_types, bool)):
        settings['plotly_proxy_authorization'] = plotly_proxy_authorization
    utils.save_json_dict(CONFIG_FILE, settings)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #3
0
ファイル: tools.py プロジェクト: shubhabrataroy/python-api
def set_credentials_file(username=None,
                         api_key=None,
                         stream_ids=None,
                         proxy_username=None,
                         proxy_password=None):
    """Set the keyword-value pairs in `~/.plotly_credentials`.

    :param (str) username: The username you'd use to sign in to Plotly
    :param (str) api_key: The api key associated with above username
    :param (list) stream_ids: Stream tokens for above credentials
    :param (str) proxy_username: The un associated with with your Proxy
    :param (str) proxy_password: The pw associated with your Proxy un

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    credentials = get_credentials_file()
    if isinstance(username, six.string_types):
        credentials['username'] = username
    if isinstance(api_key, six.string_types):
        credentials['api_key'] = api_key
    if isinstance(proxy_username, six.string_types):
        credentials['proxy_username'] = proxy_username
    if isinstance(proxy_password, six.string_types):
        credentials['proxy_password'] = proxy_password
    if isinstance(stream_ids, (list, tuple)):
        credentials['stream_ids'] = stream_ids
    utils.save_json_dict(CREDENTIALS_FILE, credentials)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #4
0
def set_config_file(plotly_domain=None, plotly_streaming_domain=None):
    """Set the keyword-value pairs in `~/.plotly/.config`.

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    settings = get_config_file()
    if isinstance(plotly_domain, six.string_types):
        settings['plotly_domain'] = plotly_domain
    if isinstance(plotly_streaming_domain, six.string_types):
        settings['plotly_streaming_domain'] = plotly_streaming_domain
    utils.save_json_dict(CONFIG_FILE, settings)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #5
0
def set_config_file(plotly_domain=None, plotly_streaming_domain=None):
    """Set the keyword-value pairs in `~/.plotly/.config`.

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    settings = get_config_file()
    if isinstance(plotly_domain, six.string_types):
        settings['plotly_domain'] = plotly_domain
    if isinstance(plotly_streaming_domain, six.string_types):
        settings['plotly_streaming_domain'] = plotly_streaming_domain
    utils.save_json_dict(CONFIG_FILE, settings)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #6
0
ファイル: tools.py プロジェクト: ErikZornWallentin/University
def set_credentials_file(username=None, api_key=None, stream_ids=None):
    """Set the keyword-value pairs in `~/.plotly_credentials`.

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    credentials = get_credentials_file()
    if isinstance(username, six.string_types):
        credentials['username'] = username
    if isinstance(api_key, six.string_types):
        credentials['api_key'] = api_key
    if isinstance(stream_ids, (list, tuple)):
        credentials['stream_ids'] = stream_ids
    utils.save_json_dict(CREDENTIALS_FILE, credentials)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #7
0
def set_credentials_file(username=None, api_key=None, stream_ids=None):
    """Set the keyword-value pairs in `~/.plotly_credentials`.

    """
    if not _file_permissions:
        raise exceptions.PlotlyError("You don't have proper file permissions "
                                     "to run this function.")
    ensure_local_plotly_files()  # make sure what's there is OK
    credentials = get_credentials_file()
    if isinstance(username, six.string_types):
        credentials['username'] = username
    if isinstance(api_key, six.string_types):
        credentials['api_key'] = api_key
    if isinstance(stream_ids, (list, tuple)):
        credentials['stream_ids'] = stream_ids
    utils.save_json_dict(CREDENTIALS_FILE, credentials)
    ensure_local_plotly_files()  # make sure what we just put there is OK
コード例 #8
0
ファイル: tools.py プロジェクト: ramosapf/python-api
def ensure_local_plotly_files():
    """Ensure that filesystem is setup/filled out in a valid way"""
    if _file_permissions:
        for fn in [CREDENTIALS_FILE, CONFIG_FILE]:
            utils.ensure_file_exists(fn)
            contents = utils.load_json_dict(fn)
            for key, val in list(_FILE_CONTENT[fn].items()):
                # TODO: removed type checking below, may want to revisit
                if key not in contents:
                    contents[key] = val
            contents_keys = list(contents.keys())
            for key in contents_keys:
                if key not in _FILE_CONTENT[fn]:
                    del contents[key]
            utils.save_json_dict(fn, contents)
    else:
        warnings.warn("Looks like you don't have 'read-write' permission to "
                      "your 'home' ('~') directory or to our '~/.plotly' "
                      "directory. That means plotly's python api can't setup "
                      "local configuration files. No problem though! You'll "
                      "just have to sign-in using 'plotly.plotly.sign_in()'. For help "
                      "with that: 'help(plotly.plotly.sign_in)'."
                      "\nQuestions? [email protected]")
コード例 #9
0
ファイル: utils.py プロジェクト: zhy0313/plotly.py
 def restore_files(self):
     if files.check_file_permissions():
         if self._credentials is not None:
             utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
         if self._config is not None:
             utils.save_json_dict(files.CONFIG_FILE, self._config)
         if self._graph_reference is not None:
             utils.save_json_dict(files.GRAPH_REFERENCE_FILE,
                                  self._graph_reference)
コード例 #10
0
ファイル: utils.py プロジェクト: AltxSF/plotly.py
 def restore_files(self):
     if files.check_file_permissions():
         if self._credentials is not None:
             utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
         if self._config is not None:
             utils.save_json_dict(files.CONFIG_FILE, self._config)
         if self._graph_reference is not None:
             utils.save_json_dict(files.GRAPH_REFERENCE_FILE,
                                  self._graph_reference)
コード例 #11
0
 def restore_files(self):
     if self._credentials and files.ensure_writable_plotly_dir():
         utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
     if self._config and files.ensure_writable_plotly_dir():
         utils.save_json_dict(files.CONFIG_FILE, self._config)
コード例 #12
0
ファイル: utils.py プロジェクト: zjw201121002/plotly.py
 def restore_files(self):
     if files.check_file_permissions():
         if self._credentials is not None:
             utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
         if self._config is not None:
             utils.save_json_dict(files.CONFIG_FILE, self._config)
コード例 #13
0
 def restore_files(self):
     if files.check_file_permissions():
         if self._credentials is not None:
             utils.save_json_dict(files.CREDENTIALS_FILE, self._credentials)
         if self._config is not None:
             utils.save_json_dict(files.CONFIG_FILE, self._config)
コード例 #14
0
 def set_graph_reference(self, graph_reference):
     if files.check_file_permissions():
         utils.save_json_dict(files.GRAPH_REFERENCE_FILE, graph_reference)
コード例 #15
0
ファイル: tools.py プロジェクト: ErikZornWallentin/University
def reset_credentials_file():
    ensure_local_plotly_files()  # make sure what's there is OK
    utils.save_json_dict(CREDENTIALS_FILE, {})
    ensure_local_plotly_files()  # put the defaults back
コード例 #16
0
 def set_graph_reference(self, graph_reference):
     if files.check_file_permissions():
         utils.save_json_dict(files.GRAPH_REFERENCE_FILE, graph_reference)
コード例 #17
0
ファイル: tools.py プロジェクト: ramosapf/python-api
def reset_credentials_file():
    ensure_local_plotly_files()  # make sure what's there is OK
    utils.save_json_dict(CREDENTIALS_FILE, {})
    ensure_local_plotly_files()  # put the defaults back