summaryrefslogtreecommitdiffstats
path: root/src/python/abcpy_test.py
blob: 28c3505bc0d5e151e2b913c09ed0f377d1488473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
import pyabc

# A new command is just a function that accepts a list of string arguments
#   The first argument is always the name of the command
#   It MUST return an integer. -1: user quits, -2: error. Return 0 for success.

# a simple command that just prints its arguments and returns success
def pytest1_cmd(args):
    print args
    return 0

# registers the command:
#   The first argument is the function
#   The second argument is the category (mainly for the ABC help command)
#   The third argument is the new command name
#   Keet the fourth argument 0, or consult with Alan
pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)

# a simple command that just prints its arguments and runs the command 'scorr -h'
def pytest2_cmd(args):
    print args
    pyabc.run_command('scorr -h')
    return 0

pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)

# Now a more complicated command with argument parsing
# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
# for more details see the optparse module: http://docs.python.org/library/optparse.html

import optparse

def pytest3_cmd(args):
    usage = "usage: %prog [options]"
    
    parser = optparse.OptionParser(usage, prog="pytest3")
    
    parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for")
    parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")

    options, args = parser.parse_args(args)
    
    if options.version:
        print sys.version
        return 0
    
    if options.cmd:
        pyabc.run_command("%s -h"%options.cmd)
        return 0
    
    return 0

pyabc.add_abc_command(pytest3_cmd, "Python-Test", "pytest3", 0)
n class="o">= "factory"; reg = <0x40000 0x10000>; read-only; }; partition@50000 { label = "firmware"; reg = <0x50000 0x7b0000>; }; }; }; }; pinctrl { state_default: pinctrl0 { gpio { ralink,group = "jtag", "mdio", "rgmii1", "rgmii1", "i2c", "uartf"; ralink,function = "gpio"; }; }; }; ethernet@10100000 { status = "okay"; port@4 { compatible = "ralink,mt7620a-gsw-port", "ralink,eth-port"; reg = <4>; phy-mode = "rgmii"; phy-handle = <&phy4>; }; port@5 { compatible = "ralink,mt7620a-gsw-port", "ralink,eth-port"; reg = <5>; phy-mode = "rgmii"; phy-handle = <&phy5>; }; mdio-bus { status = "okay"; phy4: ethernet-phy@4 { reg = <4>; phy-mode = "rgmii"; }; phy5: ethernet-phy@5 { reg = <5>; phy-mode = "rgmii"; }; }; }; gsw@10110000 { ralink,port4 = "gmac"; pinctrl-names = "default"; pinctrl-0 = <&ephy_pins>; }; sdhci@10130000 { status = "okay"; }; pcie@10140000 { status = "okay"; }; gpio-keys-polled { compatible = "gpio-keys"; #address-cells = <1>; #size-cells = <0>; poll-interval = <20>; s2 { label = "S2"; gpios = <&gpio0 1 1>; linux,code = <0x100>; }; s3 { label = "S3"; gpios = <&gpio0 2 1>; linux,code = <0x101>; }; }; };