コード例 #1
0
ファイル: app.py プロジェクト: ananelson/dexy-viewer
 def GET(self, storage_key):
     batch = Batch.load_most_recent(wrapper)
     data = batch.data_for_storage_key(storage_key)
     try:
         json.dumps(unicode(data))
         return unicode(data)
     except UnicodeDecodeError:
         return data.data()
コード例 #2
0
def grep_command(
        __cli_options=False,  # nodoc
        contents=False,  # print out the contents of each matched file
        expr="",  # An expression partially matching document name.
        key="",  # An exact document key
        keyexpr="",  # Only search for keys matching this expression
        keylimit=10,  # Maximum number of matching keys to print
        keys=False,  # List keys in documents
        limit=10,  # Maximum number of matching documents to print
        lines=False,  # maximum number of lines of content to print
        **kwargs):
    """
    Search for documents and sections within documents.

    Dexy must have already run successfully.

    You can search for documents based on exact key or inexpect expression. The
    number of documents returned is controlled by --limit.

    You can print all keys in found documents by requesting --keys, number of
    results is controlled by --keylimit.

    You can search the section names/keys in found documents by passing a
    --keyexpr

    You can print contents of documents by requesting --contents, number of
    lines of content can be controlled by --lines.

    This does not search contents of documents, just document names and
    internal section names.
    """

    artifactsdir = kwargs.get('artifactsdir', defaults['artifacts_dir'])
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)

    if not batch:
        print "you need to run dexy first"
        sys.exit(1)
    else:
        if expr:
            matches = sorted([data for data in batch if expr in data.key],
                             key=attrgetter('key'))
        elif key:
            matches = sorted([data for data in batch if key == data.key],
                             key=attrgetter('key'))
        else:
            raise dexy.exceptions.UserFeedback(
                "Must specify either expr or key")

        n = len(matches)
        if n > limit:
            print "only printing first %s of %s total matches" % (limit, n)
            matches = matches[0:limit]

        for match in matches:
            print_match(match, keys, keyexpr, contents, keylimit, lines)
コード例 #3
0
ファイル: app.py プロジェクト: ananelson/dexy-viewer
    def GET(self, expr, keyexpr=None):
        batch = Batch.load_most_recent(wrapper)

        if not expr:
            matches = sorted([data for data in batch], key=attrgetter('key'))[0:20]
        else:
            matches = sorted([data for data in batch if expr in data.key], key=attrgetter('key'))

        return render.grep(matches, expr, keyexpr)
コード例 #4
0
ファイル: grep.py プロジェクト: GWhized/dexy
def grep_command(
        __cli_options=False, # nodoc
        contents=False, # print out the contents of each matched file
        expr="", # An expression partially matching document name.
        key="", # An exact document key
        keyexpr="", # Only search for keys matching this expression
        keylimit=10, # Maximum number of matching keys to print
        keys=False, # List keys in documents
        limit=10, # Maximum number of matching documents to print
        lines=False, # maximum number of lines of content to print
        **kwargs
        ):
    """
    Search for documents and sections within documents.

    Dexy must have already run successfully.

    You can search for documents based on exact key or inexpect expression. The
    number of documents returned is controlled by --limit.

    You can print all keys in found documents by requesting --keys, number of
    results is controlled by --keylimit.

    You can search the section names/keys in found documents by passing a
    --keyexpr

    You can print contents of documents by requesting --contents, number of
    lines of content can be controlled by --lines.

    This does not search contents of documents, just document names and
    internal section names.
    """

    artifactsdir = kwargs.get('artifactsdir', defaults['artifacts_dir'])
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)
   
    if not batch:
        print "you need to run dexy first"
        sys.exit(1)
    else:
        if expr:
            matches = sorted([data for data in batch if expr in data.key],
                    key=attrgetter('key'))
        elif key:
            matches = sorted([data for data in batch if key == data.key],
                    key=attrgetter('key'))
        else:
            raise dexy.exceptions.UserFeedback("Must specify either expr or key")

        n = len(matches)
        if n > limit:
            print "only printing first %s of %s total matches" % (limit, n)
            matches = matches[0:limit]

        for match in matches:
            print_match(match, keys, keyexpr, contents, keylimit, lines)
コード例 #5
0
ファイル: app.py プロジェクト: ananelson/dexy-viewer
    def GET(self, storage_key):
        batch = Batch.load_most_recent(wrapper)
        data = batch.data_for_storage_key(storage_key)

        if data.ext in (".png", ".jpg"): # Add any other image formats here.
            return """<img title="%s" src="/raw/%s" />""" % (data.key, storage_key)
        else:
            try:
                uc = unicode(data)
                json.dumps(uc)
                return wrap_content(uc, data.ext)
            except Exception:
                return """<a href="/raw/%s">download</a>""" % storage_key
コード例 #6
0
ファイル: info.py プロジェクト: stephenhay/dexy
def links_command(
        **kwargs
        ):
    """
    Print list of links and sections found in dexy documents.
    """
    artifactsdir = kwargs.get('artifactsdir', defaults['artifacts_dir'])
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)

    if not batch:
        print "you need to run dexy first"
        sys.exit(1)

    wrapper.setup_log()
    wrapper.batch = batch

    wrapper.add_lookups()

    if wrapper.lookup_nodes:
        print_indented("Nodes:")
    for label in sorted(wrapper.lookup_nodes):
        nodes = wrapper.lookup_nodes[label]
        if len(nodes) > 1:
            print ''
            print_indented("'%s'" % label, 2)
            print_indented("Multiple nodes match %s:" % label, 4)
            for node in nodes:
                print_indented(">> %r" % node, 6)
        elif len(nodes) == 0:
            print_indented("'%s'" % label, 2)
            print_indented("NO nodes match %s" % label, 4)
        else:
            node = nodes[0]
            print_indented("'%s'" % label, 2)
            print_indented("%r" % node, 4)
        print ''

    print ''

    if wrapper.lookup_sections:
        print_indented("Sections:")
    for label in sorted(wrapper.lookup_sections):
        node = wrapper.lookup_sections[label][0]
        print_indented("'%s'" % label, 2)
        print_indented("%r" % node, 4)
        print ''
コード例 #7
0
ファイル: info.py プロジェクト: luisibanez/dexy
def info_command(
    __cli_options=False,
    expr="",  # The doc key to query. Use dexy grep to search doc keys.
    key="",  # The doc key to match exactly. Use dexy grep to search doc keys.
    artifactsdir=defaults[
        'artifacts_dir'],  # location of directory in which to store artifacts
    logdir=defaults['log_dir']  # location of directory in which to store logs
):
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)

    if expr:
        matches = sorted([data for data in batch if expr in data.key],
                         key=attrgetter('key'))
        print "search expr:", expr
    elif key:
        matches = sorted([data for data in batch if key == data.key],
                         key=attrgetter('key'))
    else:
        raise dexy.exceptions.UserFeedback("Must specify either expr or key")

    for match in matches:
        print
        print "  doc key:", match.key

        print "    data attributes:"
        for fname in sorted(INFO_ATTRS):
            print "      %s: %s" % (fname, getattr(match, fname))
        print

        print "    data methods:"
        for fname in sorted(INFO_METHODS):
            print "      %s(): %s" % (fname, getattr(match, fname)())
        print

        print "    storage methods:"
        for fname in sorted(STORAGE_METHODS):
            print "      %s(): %s" % (fname, getattr(match.storage, fname)())
        print
コード例 #8
0
ファイル: grep.py プロジェクト: aioupload/dexy
def grep_command(
        __cli_options=False, # nodoc
        expr="", # The expression to search for
        key="", # The exact document key to search for
        keyexpr="", # Only search for keys matching this expression, implies keys=True
        keys=False, # if True, try to list the keys in any found files
        keylimit=10, # maximum number of matching keys to print
        limit=10, # maximum number of matching records to print
        contents=False, # print out the contents of each matched file
        lines=False, # maximum number of lines of content to print
        artifactsdir=defaults['artifacts_dir'], # location of directory in which to store artifacts
        logdir=defaults['log_dir'] # location of directory in which to store logs
        ):
    """
    Search for a Dexy document in the previously run batch. Prints out document
    keys which include the expression.
    """
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)

    def print_keys(pkeys):
        n = len(pkeys)
        if n > keylimit:
            pkeys = pkeys[0:keylimit]
        
        for key in pkeys:
            print '  ', key

        if n > keylimit:
            print "  only printed first %s of %s total keys" % (keylimit, n)

    def print_contents(text):
        text_lines = text.splitlines()
        for i, line in enumerate(text_lines):
            if lines and i > lines-1:
                continue
            print "  ", line

        if lines and lines < len(text_lines):
            print "   only printed first %s of %s total lines" % (lines, len(text_lines))

    def print_match(match):
        print match.key, "\tcache key:", match.storage_key

        if hasattr(match, 'keys'):
            if keyexpr:
                print_keys([key for key in match.keys() if keyexpr in key])
            elif keys:
                print_keys(match.keys())

        if contents:
            if isinstance(match, Sectioned):
                for section_name, section_contents in match.data().iteritems():
                    print "  section: %s" % section_name
                    print
                    print_contents(section_contents)
                    print
            elif isinstance(match, KeyValue):
                pass
            elif isinstance(match, Generic):
                try:
                    json.dumps(unicode(match))
                    print_contents(unicode(match))
                except UnicodeDecodeError:
                    print "  not printable"

    def print_matches(matches):
        for match in matches:
            print_match(match)
   
    if not batch:
        print "you need to run dexy first"
    else:
        if expr:
            matches = sorted([data for data in batch if expr in data.key], key=attrgetter('key'))
        elif key:
            matches = sorted([data for data in batch if key == data.key], key=attrgetter('key'))
        else:
            raise dexy.exceptions.UserFeedback("Must specify either expr or key")

        n = len(matches)
        if n > limit:
            print_matches(matches[0:limit])
            print "only printed first %s of %s total matches" % (limit, n)
        else:
            print_matches(matches)
コード例 #9
0
ファイル: info.py プロジェクト: stephenhay/dexy
def info_command(
        __cli_options=False,
        expr="", # An expression partially matching document name.
        key="", # The exact document key.
        ws=False, # Whether to print website reporter keys and values.
        **kwargs
        ):
    """
    Prints metadata about a dexy document.

    Dexy must have already run successfully.

    You can specify an exact document key or an expression which matches part
    of a document name/key. The `dexy grep` command is available to help you
    search for documents and print document contents.
    """
    artifactsdir = kwargs.get('artifactsdir', defaults['artifacts_dir'])
    wrapper = init_wrapper(locals())
    wrapper.setup_log()
    batch = Batch.load_most_recent(wrapper)
    wrapper.batch = batch

    if expr:
        print "search expr:", expr
        matches = sorted([data for data in batch if expr in data.key],
                key=attrgetter('key'))
    elif key:
        matches = sorted([data for data in batch if key == data.key],
                key=attrgetter('key'))
    else:
        raise dexy.exceptions.UserFeedback("Must specify either expr or key")

    for match in matches:
        print ""
        print "  Info for Document '%s'" % match.key
        print ""
        print "  document output data type:", match.alias
        print ""

        print_indented("settings:", 2)
        for k in sorted(match._instance_settings):
            if not k in ('aliases', 'help'):
                print_indented("%s: %s" % (k, match.setting(k)), 4)

        print ""
        print_indented("attributes:", 2)
        for fname in sorted(info_attrs):
            print_indented("%s: %s" % (fname, getattr(match, fname)), 4)
        print ""
    
        print_indented("methods:", 2)
        for fname in sorted(info_methods):
            print_indented("%s(): %s" % (fname, getattr(match, fname)()), 4)
        print ""

        if storage_methods:
            print_indented("storage methods:", 2)
            for fname in sorted(storage_methods):
                print_indented("%s(): %s" % (fname, getattr(match.storage, fname)), 4)
            print ''

        if ws:
            print_indented("website reporter methods:", 2)
            print ''
            reporter = dexy.reporter.Reporter.create_instance('ws')
            reporter.wrapper = wrapper
            reporter.setup_navobj()
            reporter.help(match)
            print ''
            print_indented("active template plugins are:", 2)
            print_indented(", ".join(reporter.setting('plugins')), 4)
            print ''


        else:
            print_indented("For website reporter tags, run this command with -ws option", 4)
            print ''


        print_rewrapped("""For more information about methods available on this
        data type run `dexy datas -alias %s`""" % match.alias)
コード例 #10
0
ファイル: app.py プロジェクト: ananelson/dexy-viewer
 def GET(self, storage_key, snippet_key):
     batch = Batch.load_most_recent(wrapper)
     data = batch.data_for_storage_key(storage_key)
     return wrap_content(data[snippet_key], data.ext)
コード例 #11
0
ファイル: grep.py プロジェクト: luisibanez/dexy
def grep_command(
    __cli_options=False,  # nodoc
    expr="",  # The expression to search for
    key="",  # The exact document key to search for
    keyexpr="",  # Only search for keys matching this expression, implies keys=True
    keys=False,  # if True, try to list the keys in any found files
    keylimit=10,  # maximum number of matching keys to print
    limit=10,  # maximum number of matching records to print
    contents=False,  # print out the contents of each matched file
    lines=False,  # maximum number of lines of content to print
    artifactsdir=defaults[
        'artifacts_dir'],  # location of directory in which to store artifacts
    logdir=defaults['log_dir']  # location of directory in which to store logs
):
    """
    Search for a Dexy document in the previously run batch. Prints out document
    keys which include the expression.
    """
    wrapper = init_wrapper(locals())
    batch = Batch.load_most_recent(wrapper)

    def print_keys(pkeys):
        n = len(pkeys)
        if n > keylimit:
            pkeys = pkeys[0:keylimit]

        for key in pkeys:
            print '  ', key

        if n > keylimit:
            print "  only printed first %s of %s total keys" % (keylimit, n)

    def print_contents(text):
        text_lines = text.splitlines()
        for i, line in enumerate(text_lines):
            if lines and i > lines - 1:
                continue
            print "  ", line

        if lines and lines < len(text_lines):
            print "   only printed first %s of %s total lines" % (
                lines, len(text_lines))

    def print_match(match):
        print match.key, "\tcache key:", match.storage_key

        if hasattr(match, 'keys'):
            if keyexpr:
                print_keys([key for key in match.keys() if keyexpr in key])
            elif keys:
                print_keys(match.keys())

        if contents:
            if isinstance(match, Sectioned):
                for section_name, section_contents in match.data().iteritems():
                    print "  section: %s" % section_name
                    print
                    print_contents(section_contents)
                    print
            elif isinstance(match, KeyValue):
                pass
            elif isinstance(match, Generic):
                try:
                    json.dumps(unicode(match))
                    print_contents(unicode(match))
                except UnicodeDecodeError:
                    print "  not printable"

    def print_matches(matches):
        for match in matches:
            print_match(match)

    if not batch:
        print "you need to run dexy first"
    else:
        if expr:
            matches = sorted([data for data in batch if expr in data.key],
                             key=attrgetter('key'))
        elif key:
            matches = sorted([data for data in batch if key == data.key],
                             key=attrgetter('key'))
        else:
            raise dexy.exceptions.UserFeedback(
                "Must specify either expr or key")

        n = len(matches)
        if n > limit:
            print_matches(matches[0:limit])
            print "only printed first %s of %s total matches" % (limit, n)
        else:
            print_matches(matches)