コード例 #1
0
ファイル: path.py プロジェクト: hassanrazzak/ipython
def get_ipython_module_path(module_str):
    warn(
        "get_ipython_module_path has moved to the IPython.paths module since IPython 4.0.",
        DeprecationWarning,
        stacklevel=2)
    from IPython.paths import get_ipython_module_path
    return get_ipython_module_path(module_str)
コード例 #2
0
def img_to_slack(imagefile):
    token_file = os.path.join(
        os.path.dirname(get_ipython_module_path('BMM.functions')),
        'image_uploader_token')
    try:
        with open(token_file, "r") as f:
            token = f.read().replace('\n', '')
    except:
        post_to_slack(f'failed to post image: {imagefile}')
        return ()
    client = WebClient(token=token)
    #client = WebClient(token=os.environ['SLACK_API_TOKEN'])
    try:
        response = client.files_upload(channels='#beamtime', file=imagefile)
        assert response["file"]  # the uploaded file
    except SlackApiError as e:
        post_to_slack('failed to post image: {imagefile}')
        # You will get a SlackApiError if "ok" is False
        assert e.response["ok"] is False
        assert e.response[
            "error"]  # str like 'invalid_auth', 'channel_not_found'
        print(f"Got an error: {e.response['error']}")
    except Exception as em:
        print("EXCEPTION: " + str(em))
        report(f'failed to post image: {imagefile}', level='bold', slack=True)
コード例 #3
0
def initialize_secrets():
    '''Check that the Slack secret files are in their expected locations.
    If not, copy them from the NAS server NFS mounted at /mnt/nfs/nas1.

    '''
    STARTUP = os.path.dirname(get_ipython_module_path('BMM.functions'))
    for fname in SECRET_FILES:
        if os.path.isfile(os.path.join(STARTUP, fname)):
            print(f'{TAB}Found {fname} file: {CHECK}')
        else:
            try:
                shutil.copyfile(os.path.join(SECRETS, fname),
                                os.path.join(STARTUP, fname))
                print(f'{TAB}Copied {fname} file')
            except Exception as e:
                print(e)
                print(
                    error_msg(
                        f'{TAB}Failed to copy {os.path.join(SECRETS, fname)}!')
                )
コード例 #4
0
ファイル: path.py プロジェクト: marcosptf/fedora
def get_ipython_module_path(module_str):
    warn("get_ipython_module_path has moved to the IPython.paths module")
    from IPython.paths import get_ipython_module_path
    return get_ipython_module_path(module_str)
コード例 #5
0
ファイル: path.py プロジェクト: xguse/ipython
def get_ipython_module_path(module_str):
    warn("get_ipython_module_path has moved to the IPython.paths module")
    from IPython.paths import get_ipython_module_path
    return get_ipython_module_path(module_str)
コード例 #6
0
ファイル: test_paths.py プロジェクト: Zenigma/ipython
def test_get_ipython_module_path():
    ipapp_path = paths.get_ipython_module_path('IPython.terminal.ipapp')
    assert_isfile(ipapp_path)
コード例 #7
0
def test_get_ipython_module_path():
    ipapp_path = paths.get_ipython_module_path('IPython.terminal.ipapp')
    assert_isfile(ipapp_path)
コード例 #8
0
ファイル: path.py プロジェクト: Carreau/ipython
def get_ipython_module_path(module_str):
    warn("get_ipython_module_path has moved to the IPython.paths module since IPython 4.0.", stacklevel=2)
    from IPython.paths import get_ipython_module_path
    return get_ipython_module_path(module_str)
コード例 #9
0
def test_get_ipython_module_path():
    ipapp_path = paths.get_ipython_module_path('IPython.terminal.ipapp')
    nt.assert_true(os.path.isfile(ipapp_path))
コード例 #10
0
def BMM_log_info(message):
    chmod(BMM_log_master_file, 0o644)
    chmod(BMM_nas_log_file, 0o644)
    entry = ''
    for line in message.split('\n'):
        entry += '    ' + line + '\n'
    BMM_logger.info(entry)
    chmod(BMM_log_master_file, 0o444)
    chmod(BMM_nas_log_file, 0o444)


## small effort to obfuscate the web hook URL, which is secret-ish.  See:
##   https://api.slack.com/messaging/webhooks#create_a_webhook
## in the future, this could be an ini with per-user channel URLs...
slack_secret = os.path.join(
    os.path.dirname(get_ipython_module_path('BMM.functions')), 'slack_secret')
try:
    with open(slack_secret, "r") as f:
        default_slack_channel = f.read().replace('\n', '')
except:
    print(error_msg('\t\t\tslack_secret file not found!'))


def post_to_slack(text):
    try:
        channel = BMMuser.slack_channel
    except:
        channel = default_slack_channel
    if channel is None:
        channel = default_slack_channel
    post = {"text": "{0}".format(text)}