Skip to content

Commit

Permalink
clean up the use of globals in the samples -- some missing, many extr…
Browse files Browse the repository at this point in the history
…aneous
  • Loading branch information
JoelBender committed Aug 26, 2016
1 parent 2f8888f commit 17160db
Show file tree
Hide file tree
Showing 28 changed files with 136 additions and 194 deletions.
4 changes: 0 additions & 4 deletions samples/CommandableMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None

#
# CommandableMixin
#
Expand Down
1 change: 0 additions & 1 deletion samples/ConsoleCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,3 @@ def main():

if __name__ == "__main__":
main()

4 changes: 0 additions & 4 deletions samples/MultiStateValueObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None

#
# __main__
#
Expand Down
8 changes: 1 addition & 7 deletions samples/MultipleReadProperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

# point list
# set according to your device
# point list, set according to your device
point_list = [
('1.2.3.4', 'analogValue', 1, 'presentValue'),
('1.2.3.4', 'analogValue', 2, 'presentValue'),
Expand Down
4 changes: 0 additions & 4 deletions samples/RandomAccumulatorObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None

#
# RandomUnsignedValueProperty
#
Expand Down
5 changes: 0 additions & 5 deletions samples/RandomAnalogValueObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
# settings
RANDOM_OBJECT_COUNT = int(os.getenv('RANDOM_OBJECT_COUNT', 10))

# globals
this_device = None
this_application = None

#
# RandomValueProperty
#
Expand Down Expand Up @@ -125,6 +121,5 @@ def main():

_log.debug("fini")


if __name__ == "__main__":
main()
11 changes: 5 additions & 6 deletions samples/ReadProperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

Expand Down Expand Up @@ -151,7 +150,9 @@ def do_rtn(self, args):
# __main__
#

try:
def main():
global this_application

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -189,7 +190,5 @@ def do_rtn(self, args):

_log.debug("fini")

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions samples/ReadPropertyAny.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

#
# ReadPropertyAnyApplication
Expand Down Expand Up @@ -136,6 +134,8 @@ def do_read(self, args):
#

def main():
global this_application

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down
3 changes: 1 addition & 2 deletions samples/ReadPropertyMultiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ def do_read(self, args):

def main():
global this_application
global this_device
global this_console

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down
4 changes: 0 additions & 4 deletions samples/ReadPropertyMultipleServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None

#
# RandomValueProperty
#
Expand Down
14 changes: 7 additions & 7 deletions samples/ReadRange.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

#
# ReadRangeApplication
Expand Down Expand Up @@ -124,7 +122,9 @@ def do_readrange(self, args):
# __main__
#

try:
def main():
global this_application

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -160,7 +160,7 @@ def do_readrange(self, args):

run()

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
12 changes: 7 additions & 5 deletions samples/ReadWriteFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def do_writestream(self, args):
# __main__
#

try:
def main():
global this_application

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -263,7 +265,7 @@ def do_writestream(self, args):

run()

except Exception as err:
_log.exception("an error has occurred: %s", err)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions samples/ReadWriteFileServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,5 +218,7 @@ def main():

run()

_log.debug("fini")

if __name__ == "__main__":
main()
14 changes: 7 additions & 7 deletions samples/ReadWriteProperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

#
# ReadPropertyApplication
Expand Down Expand Up @@ -234,7 +232,9 @@ def do_rtn(self, args):
# __main__
#

try:
def main():
global this_application

# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -270,7 +270,7 @@ def do_rtn(self, args):

run()

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
16 changes: 6 additions & 10 deletions samples/RecurringMultipleReadProperty.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

# point list
point_list = [
('1.2.3.4', 'analogValue', 1, 'presentValue'),
Expand Down Expand Up @@ -150,7 +145,7 @@ def confirmation(self, apdu):
# __main__
#

try:
def main():
# parse the command line arguments
parser = ConfigArgumentParser(description=__doc__)

Expand All @@ -176,6 +171,7 @@ def confirmation(self, apdu):

# make a dog
this_application = PrairieDog(args.interval, this_device, args.ini.address)
if _debug: _log.debug(" - this_application: %r", this_application)

# get the services supported
services_supported = this_application.get_services_supported()
Expand All @@ -188,7 +184,7 @@ def confirmation(self, apdu):

run()

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
10 changes: 5 additions & 5 deletions samples/RecurringTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def process_task(self):
# __main__
#

try:
def main():
# parse the command line arguments
parser = ArgumentParser(description=__doc__)

Expand All @@ -68,7 +68,7 @@ def process_task(self):

run()

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
13 changes: 4 additions & 9 deletions samples/SampleApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None

#
# SampleApplication
#
Expand Down Expand Up @@ -61,7 +57,7 @@ def confirmation(self, apdu):
# __main__
#

try:
def main():
# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -93,8 +89,7 @@ def confirmation(self, apdu):

run()

except Exception as err:
_log.exception("an error has occurred: %s", err)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
14 changes: 4 additions & 10 deletions samples/SampleConsoleCmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@
_debug = 0
_log = ModuleLogger(globals())

# globals
this_device = None
this_application = None
this_console = None

#
# SampleApplication
#
Expand Down Expand Up @@ -70,7 +65,7 @@ def do_nothing(self, args):
# __main__
#

try:
def main():
# parse the command line arguments
args = ConfigArgumentParser(description=__doc__).parse_args()

Expand Down Expand Up @@ -106,8 +101,7 @@ def do_nothing(self, args):

run()

except Exception as error:
_log.exception("an error has occurred: %s", error)
finally:
_log.debug("finally")
_log.debug("fini")

if __name__ == "__main__":
main()
Loading

0 comments on commit 17160db

Please sign in to comment.