__main__.py 3.98 KB
Newer Older
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
1
2
3
4
5
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
Philipp Gast's avatar
Philipp Gast committed
6
#   myplotlib v3.0.1,
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
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
#
#   @file      __main__.py
#   @author    Yori 'AGy' Fournier
#   @licence   CC-BY-SA
#
#   main program of the module to use in command-line mode.
#   for printing usage:
#
#            > python myplotlib -h
#
#   @section Test
#
#   run a few Test to verify integrity of library.
#
#   @section Plot
#
#   interface to the plot scripts
#
#   @section History
#
#   v 0.0.0 - __main__.py file for the myplotlib module
#             no tests and no plots
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
34
from . import D_HIERARCHY
35
from . import INFO, SPCE, DBUG
36
37
38
39
40
41
42

if D_HIERARCHY in ('CLIENT', 'client', 'local', 'LOCAL'):
    from . import myTest, testList
    from .test import __dict__ as availTests
else:
    from socket import socket, AF_INET, SOCK_STREAM
    from . import D_HOST, D_PORT
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
43
44
45
46
47
48
49
50

import sys
import getopt

# LOCAL VARIABLE
run4Plot = False
arg4Plot = ''
run4Test = False
51
debug    = False
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
52
53
54
55
56
57
58
59
60
61
62
63
64

# GET PASSED OPTIONS --------------------------------------------------- 
usage = '''
{0}Usage:       python mfdPlot [-h]
{1}                            [-t/--test [all/<num of test>]
{1}                            [-p/--plot <Name of the Plot>]
{1}                            [-a/--args <String of the arguments>]
{1}                            [--debug]
'''.format(INFO, SPCE)

# GET OPT
try:
    opts, args = getopt.getopt(
65
        sys.argv[1:], "htp:", ["test=", "plot=", "args=", "debug", "server"])
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
66
67
68
69
70
71
72
73
74
75
    
except getopt.GetoptError:
    print(usage)
    sys.exit(1)

# CASE OPT
for opt, arg in opts:
    if(opt == '-h'):
        print(usage)
        sys.exit(0)
76
    
77
    elif opt in ("-t"):
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
78
        run4Test = True
79
    
80
81
82
83
84
    elif opt in ("--test"):
        run4Test = True
        tests = arg.split(', ')
        testList = []
        for test in tests:
Yori Fournier's avatar
Yori Fournier committed
85
86
            if test in availTests.keys():
                testList.append(availTests[test])
87
88
89
90
91
        
        if len(testList) == 0:
            print(" > sevr-: you need to give valid tests to be tested.")
            exit(1)
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
92
93
94
    elif opt in ("-p", "--plot"):
        run4Plot = True
        arg4Plot = str(arg)
95
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
96
    elif opt in ("--debug"):
97
        debug = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
98

99
100
101
    elif opt in ("--server"):
        run4server = True        

Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
102
103
104
105

# SECTION: TESTS ------------------------------------------------------
if run4Test:

106
107
108
109
    if debug:
        print(DBUG + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
    else:
        print(INFO + '{title:{c}^{n}}'.format(title=' Run for Test ', c='=', n=72))
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
110
        
111
112
    fail = []
    status = True
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
113

114
115
    print(INFO + "TESTS: ")
    for test in testList:
116
        print('\n')
117
        print(INFO + '{title:{c}^{n}}'.format(title=' ' + str(test.__name__) + ' ', c='=', n=72))
118
119
120
121
122
123
124
        testStatus = myTest(test, True, fail, debug)  # function, expected, fail, debug
        if testStatus:
            print(INFO + 72 * '-' + " [PASSED]")
        else:
            print(INFO + 72 * '-' + " [FAILED] !")
        
        status = status and testStatus
125
    
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
126
    # Print final status
127
    print('\n')
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
128
129
130
131
132
133
134
135
136
137
138
139
140
    print(INFO + 'Status of test series: ' + str(status))
    if not status:
        print(SPCE + 'Number of Failed Tests: ' + str(len(fail)))
        print(SPCE + 'List of Failed Tests: ')
        for test in fail:
            print(SPCE + '\t- ' + str(test))

# SECTION: PLOTS ------------------------------------------------------
elif run4Plot:
    
    print(INFO + '{title:{c}^{n}}'.format(title=' Run for Plot ', c='=', n=72))
  
#  try:
141
142
#    data = arg4Plot
#    somePlottingRoutine(data)
Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
143
144
145
146
147
148
#  except:
#    print('\n'+SEVR+"There is something wrong with your arguments.")
#    print(usage)
#    print(INFO+"To start interactively:")
#    print(SPCE+">> from mfdPlot import * \n")

149
150
151
152
153
154
155
156
elif run4server:

    from .server import Server
    
    server = Server()
    server.init()
    server.run()

Yori 'AGy' Fournier's avatar
Yori 'AGy' Fournier committed
157
158
159
160
161
else:

    print(usage)