Beispiel #1
0
def load(request):
    response, parameters = validate_request(request)

    if response.status_code == 204:
        image = manager.load(parameters['address'], parameters['name'])
        if image is not None:
            mimetype, encoding = mimetypes.guess_type(image)
            response = HttpResponse(mimetype=mimetype)
            response['Content-Disposition'] = 'attachment; filename=%s' % parameters['name']
            response.write(image)
            response.status_code = 200
    return response
Beispiel #2
0
def load(request):
    response, parameters = validate_request(request)

    if response.status_code == 204:
        image = manager.load(parameters['address'], parameters['name'])
        if image is not None:
            mimetype, encoding = mimetypes.guess_type(image)
            response = HttpResponse(mimetype=mimetype)
            response['Content-Disposition'] = 'attachment; filename=%s' % name
            response.write(image)
            response.status_code = 200
    return response
def load(request):
    '''
    calls the methods of the package manager (loads an image)
    and returns File or None to the end of the process.
    '''
    response, parameters = validate_request(request)

    if response.status_code == 204:
        image = manager.load(parameters['address'], parameters['name'])
        if image is not None:
            mimetype, encoding = mimetypes.guess_type(image)
            response = HttpResponse(mimetype=mimetype)
            response['Content-Disposition'] = 'attachment; filename=%s' % parameters['name']
            response.write(image)
            response.status_code = 200
    return response
                                   n_samples=samples)
    ms = MeanShift(bandwidth=bandwidth, bin_seeding=True).fit(X)
    print('ms')
    #print(silhouette_score(X, ms.labels_))
    #print(calinski_harabaz_score(X, ms.labels_))
    return ms


def docs2clusters(labels, clusters):
    docs = list(zip(labels, clusters.tolist()))
    return docs


def cluster_docs(cluster, clusters_docs):
    if cluster < 0: return [d for d, c in clusters_docs]
    else: return [d for d, c in clusters_docs if c == cluster]


def cluster_words(cluster, clusters_docs, docs, count=10):
    clust_docs = cluster_docs(cluster, clusters_docs)
    tagged_docs = [d for d in docs if d.tags[0] in clust_docs]
    words = [word for d in tagged_docs for word in d.words]
    topic_words = Counter(words).most_common(count)
    return topic_words


if __name__ == '__main__':
    import manager
    import doc2vec
    vectors = manager.load(os.path.join(manager.PICKLES_DIR, 'vectors.pkl'))
    manager.save(clusterers, clusters_pkl)
Beispiel #5
0
#!/user/bin/env python3

""" Bootstrap the environment and handle the event loop. """

import asyncio
import time
import aiohttp
import manager
from env import MODULES, UTILS, STATS, GLOBAL

STATS['birth'] = time.time()

# Bootstrap the module manager
UTILS['manager'] = manager.load('manager')
del manager

# Load the slack class in via module manager
MODULES['slack'] = UTILS['manager'].load('slack')
UTILS['slack'] = MODULES['slack'].Slack()

# Load the mysql class in via module manager
MODULES['mysql'] = UTILS['manager'].load('mysql')
UTILS['mysql'] = MODULES['mysql'].Database()

# Load any custom commands that are present
UTILS['manager'].scan()

# Create the main event loop and socket
GLOBAL['loop'] = asyncio.get_event_loop()
GLOBAL['loop'].set_debug(True)
GLOBAL['socket'] = aiohttp.ClientSession(loop=GLOBAL['loop'])
Beispiel #6
0
def interact():
    banner = "\033[1mSnimpy\033[0m (%s) -- An interactive SNMP tool.\n" % VERSION
    banner += "  load        -> load an additional MIB\n"
    banner += "  M           -> manager object"

    local = {"conf": conf, "M": manager.Manager, "load": manager.load, "timedelta": timedelta, "snmp": manager.snmp}

    if len(sys.argv) <= 1:
        manager.Manager._complete = True

    for ms in conf.mibs:
        manager.load(ms)

    globals().update(local)

    if len(sys.argv) > 1:
        sys.argv = sys.argv[1:]
        execfile(sys.argv[0], local)
        return

    try:
        import rlcompleter
        import readline
    except ImportError:
        readline = None
    try:
        try:
            # ipython >= 0.11
            from IPython.frontend.terminal.embed import InteractiveShellEmbed
            from IPython.config.loader import Config

            cfg = Config()
            try:
                # >= 0.12
                from IPython.core.prompts import PromptManager

                cfg.PromptManager.in_template = "Snimpy [\\#]> "
                cfg.PromptManager.out_template = "Snimpy [\\#]: "
            except ImportError:
                # 0.11
                cfg.InteractiveShellEmbed.prompt_in1 = "Snimpy [\\#]> "
                cfg.InteractiveShellEmbed.prompt_out = "Snimpy [\\#]: "
            if conf.ipythonprofile:
                cfg.InteractiveShellEmbed.profile = conf.ipythonprofile
            shell = InteractiveShellEmbed(config=cfg, banner1=banner, user_ns=local)
            shell.InteractiveTB.tb_offset += 1  # Not interested by traceback in this module
        except ImportError:
            # ipython < 0.11
            from IPython.Shell import IPShellEmbed

            argv = ["-prompt_in1", "Snimpy [\\#]> ", "-prompt_out", "Snimpy [\\#]: "]
            if conf.ipythonprofile:
                argv += ["-profile", conf.ipythonprofile]
            shell = IPShellEmbed(argv=argv, banner=banner, user_ns=local)
            shell.IP.InteractiveTB.tb_offset += 1  # Not interested by traceback in this module
    except ImportError:
        shell = None

    if shell and conf.ipython:
        shell()
    else:
        if readline:
            if conf.histfile:
                try:
                    readline.read_history_file(os.path.expanduser(conf.histfile))
                except IOError:
                    pass
                atexit.register(lambda: readline.write_history_file(os.path.expanduser(conf.histfile)))

            readline.set_completer(rlcompleter.Completer(local).complete)
            readline.parse_and_bind("tab: menu-complete")
        sys.ps1 = conf.prompt
        code.interact(banner=banner, local=local)
def load_from_s3():
    manager.load()
Beispiel #8
0
def interact():
    banner = "\033[1mSnimpy\033[0m (%s) -- An interactive SNMP tool.\n" % VERSION
    banner += "  load        -> load an additional MIB\n"
    banner += "  M           -> manager object"

    local = {
        "conf": conf,
        "M": manager.Manager,
        "load": manager.load,
        "timedelta": timedelta,
        "snmp": manager.snmp
    }

    if len(sys.argv) <= 1:
        manager.Manager._complete = True

    for ms in conf.mibs:
        manager.load(ms)

    globals().update(local)

    if len(sys.argv) > 1:
        sys.argv = sys.argv[1:]
        execfile(sys.argv[0], local)
        return

    try:
        import rlcompleter
        import readline
    except ImportError:
        readline = None
    try:
        try:
            # ipython >= 0.11
            from IPython.frontend.terminal.embed import InteractiveShellEmbed
            from IPython.config.loader import Config
            cfg = Config()
            try:
                # >= 0.12
                from IPython.core.prompts import PromptManager
                cfg.PromptManager.in_template = "Snimpy [\\#]> "
                cfg.PromptManager.out_template = "Snimpy [\\#]: "
            except ImportError:
                # 0.11
                cfg.InteractiveShellEmbed.prompt_in1 = "Snimpy [\\#]> "
                cfg.InteractiveShellEmbed.prompt_out = "Snimpy [\\#]: "
            if conf.ipythonprofile:
                cfg.InteractiveShellEmbed.profile = conf.ipythonprofile
            shell = InteractiveShellEmbed(config=cfg,
                                          banner1=banner,
                                          user_ns=local)
            shell.InteractiveTB.tb_offset += 1  # Not interested by traceback in this module
        except ImportError:
            # ipython < 0.11
            from IPython.Shell import IPShellEmbed
            argv = [
                "-prompt_in1", "Snimpy [\\#]> ", "-prompt_out",
                "Snimpy [\\#]: "
            ]
            if conf.ipythonprofile:
                argv += ["-profile", conf.ipythonprofile]
            shell = IPShellEmbed(argv=argv, banner=banner, user_ns=local)
            shell.IP.InteractiveTB.tb_offset += 1  # Not interested by traceback in this module
    except ImportError:
        shell = None

    if shell and conf.ipython:
        shell()
    else:
        if readline:
            if conf.histfile:
                try:
                    readline.read_history_file(
                        os.path.expanduser(conf.histfile))
                except IOError:
                    pass
                atexit.register(lambda: readline.write_history_file(
                    os.path.expanduser(conf.histfile)))

            readline.set_completer(rlcompleter.Completer(local).complete)
            readline.parse_and_bind("tab: menu-complete")
        sys.ps1 = conf.prompt
        code.interact(banner=banner, local=local)