Conditions | 6 |
Total Lines | 57 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import sys |
||
98 | def main(): |
||
99 | ''' |
||
100 | When run from the command line, pass in a value of seconds as an argument |
||
101 | to set the packet loss for reporting period. |
||
102 | |||
103 | for example, to report packet loss statistics every hour, run the following command |
||
104 | (if rsudp is installed in your environment, i.e. activate using ``conda activate rsudp``, then): |
||
105 | |||
106 | .. code-block:: bash |
||
107 | |||
108 | rs-packetloss -s 3600 -p 18001 |
||
109 | |||
110 | ''' |
||
111 | |||
112 | hlp_txt = ''' |
||
113 | ######################################################## |
||
114 | ## R A S P B E R R Y S H A K E ## |
||
115 | ## UDP Packet Loss Reporter ## |
||
116 | ## by Richard Boaz ## |
||
117 | ## Copyleft 2019 ## |
||
118 | ## ## |
||
119 | ## Reports data packet loss over a specified period ## |
||
120 | ## of seconds. ## |
||
121 | ## ## |
||
122 | ## Supply -p (port) and -f (frequency) to change ## |
||
123 | ## the port and frequency to report packet loss ## |
||
124 | ## statistics. ## |
||
125 | ## ## |
||
126 | ## Requires: ## |
||
127 | ## - rsudp ## |
||
128 | ## ## |
||
129 | ## The following example sets the port to 18001 ## |
||
130 | ## and report frequency to 1 hour ## |
||
131 | ## ## |
||
132 | ######################################################## |
||
133 | ## ## |
||
134 | ## $ rs-packetloss -p 18001 -f 3600 ## |
||
135 | ## ## |
||
136 | ######################################################## |
||
137 | |||
138 | ''' |
||
139 | |||
140 | f, p = 60, 8888 |
||
141 | opts, args = getopt.getopt(sys.argv[1:], 'hp:f:', ['help', 'port=', 'frequency=']) |
||
142 | for o, a in opts: |
||
143 | if o in ('-h, --help'): |
||
144 | print(hlp_txt) |
||
145 | exit(0) |
||
146 | if o in ('-p', 'port='): |
||
147 | p = int(a) |
||
148 | if o in ('-f', 'frequency='): |
||
149 | f = int(a) |
||
150 | try: |
||
151 | run(printFREQ=f, port=p) |
||
152 | except KeyboardInterrupt: |
||
153 | print('') |
||
154 | printM('Quitting...') |
||
155 | |||
162 |