From 3413dee5765bce636bb575f5df149813f6e50066 Mon Sep 17 00:00:00 2001 From: Adam Fast Date: Fri, 28 Jun 2013 23:38:28 -0500 Subject: [PATCH] Attempt to load configuration from a module my_ipsc_config.py to allow leaving your systems configured without editing the main Python source file - and as that file is expected to have IPs / keys that may not be intended for the public, tell git to ignore that file. --- .gitignore | 2 + ipsc.py | 151 +++++++++++++++++++++++++++-------------------------- 2 files changed, 79 insertions(+), 74 deletions(-) diff --git a/.gitignore b/.gitignore index d37a789..8ae94f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .DS_Store .dropbox Icon +my_ipsc_config.py +*.pyc diff --git a/ipsc.py b/ipsc.py index 9ebc6e8..9679a63 100644 --- a/ipsc.py +++ b/ipsc.py @@ -62,84 +62,87 @@ logger = logging.getLogger('ipsc') # Data structure for holding IPSC information -NETWORK = { - 'IPSC1': { - 'LOCAL': { - 'DESCRIPTION': 'IPSC Network #1', - 'MODE': b'\x6A', - 'FLAGS': b'\x00\x00\x80\xDC', - 'PORT': 50001, - 'RADIO_ID': binascii.unhexlify('00000001'), - 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000001') +try: + from my_ipsc_config import NETWORK +except ImportError: + NETWORK = { + 'IPSC1': { + 'LOCAL': { + 'DESCRIPTION': 'IPSC Network #1', + 'MODE': b'\x6A', + 'FLAGS': b'\x00\x00\x80\xDC', + 'PORT': 50001, + 'RADIO_ID': binascii.unhexlify('00000001'), + 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000001') + }, + 'MASTER': { + 'IP': '1.1.1.1', + 'MODE': b'\x6A', + 'PORT': 50000, + 'RADIO_ID': '', + }, + 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT + #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, + ] }, - 'MASTER': { - 'IP': '1.1.1.1', - 'MODE': b'\x6A', - 'PORT': 50000, - 'RADIO_ID': '', + 'IPSC2': { + 'LOCAL': { + 'DESCRIPTION': 'IPSC Network #1', + 'MODE': b'\x6A', + 'FLAGS': b'\x00\x00\x80\xDC', + 'PORT': 50002, + 'RADIO_ID': binascii.unhexlify('00000002'), + 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000022') + }, + 'MASTER': { + 'IP': '2.2.2.2', + 'MODE': b'\x6A', + 'PORT': 50000, + 'RADIO_ID': '', + }, + 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT + #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, + ] }, - 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT - #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, - ] - }, - 'IPSC2': { - 'LOCAL': { - 'DESCRIPTION': 'IPSC Network #1', - 'MODE': b'\x6A', - 'FLAGS': b'\x00\x00\x80\xDC', - 'PORT': 50002, - 'RADIO_ID': binascii.unhexlify('00000002'), - 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000022') + 'IPSC3': { + 'LOCAL': { + 'DESCRIPTION': 'IPSC Network #1', + 'MODE': b'\x6A', + 'FLAGS': b'\x00\x00\x80\xDC', + 'PORT': 50003, + 'RADIO_ID': binascii.unhexlify('00000003'), + 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000333') + }, + 'MASTER': { + 'IP': '3.3.3.3', + 'MODE': b'\x6A', + 'PORT': 50000, + 'RADIO_ID': '', + }, + 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT + #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, + ] }, - 'MASTER': { - 'IP': '2.2.2.2', - 'MODE': b'\x6A', - 'PORT': 50000, - 'RADIO_ID': '', - }, - 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT - #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, - ] - }, - 'IPSC3': { - 'LOCAL': { - 'DESCRIPTION': 'IPSC Network #1', - 'MODE': b'\x6A', - 'FLAGS': b'\x00\x00\x80\xDC', - 'PORT': 50003, - 'RADIO_ID': binascii.unhexlify('00000003'), - 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000000333') - }, - 'MASTER': { - 'IP': '3.3.3.3', - 'MODE': b'\x6A', - 'PORT': 50000, - 'RADIO_ID': '', - }, - 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT - #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, - ] - }, - 'IPSC4': { - 'LOCAL': { - 'DESCRIPTION': 'IPSC Network #1', - 'MODE': b'\x6A', - 'FLAGS': b'\x00\x00\x80\xDC', - 'PORT': 50004, - 'RADIO_ID': binascii.unhexlify('00000004'), - 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000004444') - }, - 'MASTER': { - 'IP': '4.4.4.4', - 'MODE': b'\x6A', - 'PORT': 50000, - 'RADIO_ID': '', - }, - 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT - #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, - ] + 'IPSC4': { + 'LOCAL': { + 'DESCRIPTION': 'IPSC Network #1', + 'MODE': b'\x6A', + 'FLAGS': b'\x00\x00\x80\xDC', + 'PORT': 50004, + 'RADIO_ID': binascii.unhexlify('00000004'), + 'AUTH_KEY': binascii.unhexlify('0000000000000000000000000000000000004444') + }, + 'MASTER': { + 'IP': '4.4.4.4', + 'MODE': b'\x6A', + 'PORT': 50000, + 'RADIO_ID': '', + }, + 'PEERS': [ # each list entry will be a dictionary for IP, RADIO ID and PORT + #{'IP': '100.200.1.1', 'PORT': 50000, 'RADIO_ID': b'\x00\x00\x00\xFF'}, + ] + } } -} # Known IPSC Message Types