예제 #1
0
파일: main.py 프로젝트: johnsonc/swarm
def main (args):
    import locale
    import gettext

    import pygtk; pygtk.require('2.0');

    import gobject
    from gobject.option import OptionParser, make_option

    import gtk

    import maindialog
    import config

    locale.setlocale (locale.LC_ALL, "")
    gettext.install (config.PACKAGE, config.LOCALEDIR)

    parser = OptionParser (
            option_list = [
		    # FIXME: remove this when we can get all the default
		    # options
                    make_option ("--version",
                                 action="store_true",
                                 dest="version",
                                 help=config.VERSION),
                ])
    parser.parse_args (args)

    if parser.values.version:
        # Translators: %s is the version number 
        print _("Simple Menu Editor %s") % (config.VERSION)
    else:
        dialog = maindialog.MenuEditorDialog (args)
        gtk.main ()
예제 #2
0
#!/usr/bin/env python
# gnome-python/pygobject/examples/option.py

from gobject.option import OptionGroup, OptionParser, make_option

group = OptionGroup("example",
                    "OptionGroup Example",
                    "Shows all example options",
                    option_list=[
                        make_option("--example",
                                    action="store_true",
                                    dest="example",
                                    help="An example option."),
                    ])

parser = OptionParser(
    "NAMES ...",
    description="A simple gobject.option example.",
    option_list=[
        make_option("--file",
                    "-f",
                    type="filename",
                    action="store",
                    dest="file",
                    help="A filename option"),
        # ...
    ])

parser.add_option_group(group)

parser.parse_args()
예제 #3
0
#!/usr/bin/env python
# gnome-python/pygobject/examples/option.py

from gobject.option import OptionGroup, OptionParser, make_option

group = OptionGroup("example", "OptionGroup Example", "Shows all example options",
    option_list = [
        make_option("--example",
                    action="store_true",
                    dest="example",
                    help="An example option."),
    ])

parser = OptionParser("NAMES ...",
    description="A simple gobject.option example.",
    option_list = [
        make_option("--file", "-f",
                    type="filename",
                    action="store",
                    dest="file",
                    help="A filename option"),
        # ...
    ])

parser.add_option_group(group)

parser.parse_args()

print "group: example ", group.values.example
print "parser: file", parser.values.file
예제 #4
0
def main(argv):
    """
    """
    group = OptionGroup("example", "OptionGroup Example", \
        "Shows all example options",
        option_list = [
            make_option("--example",
                        action="store_true",
                        dest="example",
                        help="An example option."),
        ]
    )

    parser = OptionParser("NAMES ...",
        description="A simple gobject.option example.",
        option_list = [
            make_option("--file", "-f",
                        type="filename",
                        action="store",
                        dest="file",
                        help="A filename option"),
            # ...
        ])

    parser.add_option_group(group)

    parser.parse_args()
    
    lineBody = SkipTo(lineEnd).setParseAction(mustBeNonBlank)

    # now define a line with a trailing lineEnd, to be replaced with a space character
    textLine = lineBody + Suppress(lineEnd).setParseAction(replaceWith(" "))

    # define a paragraph, with a separating lineEnd, to be replaced with a double newline
    para = OneOrMore(textLine) + Suppress(lineEnd).setParseAction(replaceWith("\n\n"))

    # run a test
    test = """
        Now is the
        time for
        all
        good men
        to come to

        the aid of their
        country.
    """
    print para.transformString(test)

    subdir_dir = Word(alphas, alphanums+"_")
    #macroDef = Suppress("SUBDIRS") + Suppress("=") + restOfLine
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_1line))
    print("1: subdirs of subdirs_1line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=True )
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + delimitedList( subdir_dir, " ", combine=False)
    macros = list(subdir_dir_list.searchString(subdirs_2line))
    print("2: subdirs of subdirs_2line are {}".format(macros))

    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        Suppress(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns a list!
    subdir_dir_list = Suppress("SUBDIRS") + Suppress("=") + \
        delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_3line))
    print("3: subdirs of subdirs_3line are {}".format(macros))

    # This returns nothing because SUBDIRS is commented out!
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, " ", combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_4line))
    print("4: subdirs of subdirs_4line are {}".format(macros))

    # This returns 
    subdir_dir_list = Suppress(lineStart) + Suppress("SUBDIRS") + \
        Suppress("=") + delimitedList( subdir_dir, OneOrMore(" "), combine=False) + \
        SkipTo(lineEnd)
    macros = list(subdir_dir_list.searchString(subdirs_5line))
    print("5: subdirs of subdirs_5line are {}".format(macros))
    print("5a: subdirs of subdirs_5line are {}".\
        format(subdir_dir_list.scanString(subdirs_5line)))

    print "group: example ", group.values.example
    print "parser: file", parser.values.file

    res = 1
    try:
        pyparsing()
        print('{}'.format("pyparsing() done."))
        lun_q = r'''Lun:\s*(\d+(?:\s+\d+)*)'''
        s = '''Lun: 0 1 2 3 295 296 297 298'''

        r = re.search(lun_q, s)
        luns = None
        if r:
            luns = r.group(1).split()

            # optionally, also convert luns from strings to integers
            luns = [int(lun) for lun in luns]
            print('luns: {}'.format(luns))
        else:
            print('{}'.format("Got no Luns"))

        print('smthng: {}'.format(smthng()))
        print(re.findall(r"####(.*?)\s(.*?)\s####", string, re.DOTALL))
        
        # Catches testsuite in [SUBDIRS =   testsuite]
        print('1: {}'.format(re.findall(r'''^SUBDIRS =\s+(.*)''', \
            subdirs_1line, re.MULTILINE)))

        # Catches ['SUBDIRS', 'testsuite', 'src'] in [SUBDIRS =   testsuite src]
        # *** THIS IS THE 1! ***
        # Works for an 
        print('2: {}'.format(re.findall(r'''=\s*(\w+(?:\s+\w+)*)\s*''', \
            subdirs_2line, re.MULTILINE)))
        for iter in re.finditer(r'''(\w+)\s+''', \
            subdirs_2line, re.MULTILINE | re.VERBOSE):
            print('iter: {}'.format(iter.span()))

        # Catches ['SUBDIRS', 'testsuite', 'src'] in [SUBDIRS =   testsuite src]
        print('3: {}'.format(re.findall(
            r'''SUBDIRS\s*=\s*(\w+(?:\s+\w+)*)\s*''', subdirs_3line))
        )
        for iter in re.finditer(r'''SUBDIRS\s*=\s*(\w+(?:\s+\w+)*)\s*''', \
            subdirs_3line, re.MULTILINE | re.VERBOSE):
            print('iter: {}'.format(iter.group()))

        # Catches ['SUBDIRS', 'testsuite', 'src'] in [SUBDIRS =   testsuite src]
        print('4: {}'.format(re.findall(
            r'''^SUBDIRS\s*=\s*(\w+(?:\s+\w+)*)\s*''', subdirs_4line))
        )
        for iter in re.finditer(r'''^SUBDIRS\s*=\s*(\w+(?:\s+\w+)*)\s*''', \
            subdirs_4line, re.MULTILINE | re.VERBOSE):
            print('iter: {}'.format(iter.group()))

        """ Reference: <http://stackoverflow.com/questions/8651347/
        regex-to-match-a-capturing-group-one-or-more-times>

        regx = re.compile('(?:(?<= )|(?<=\A)|(?<=\r)|(?<=\n))'
                  '(\d\d)(\d\d)?(\d\d)?'
                  '(?= |\Z|\r|\n)')

        for s in ('   112233  58975  6677  981  897899\r',
                  '\n123456 4433 789101 41586 56 21365899 362547\n',
                  '0101 456899 1 7895'):
            print repr(s),'\n',regx.findall(s),'\n'
        """
        res = 0
    except Exception, err:
        sys.stderr.write("{}".format(err))