Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faraday-Proxy PyPi Support #203

Merged
merged 48 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
dc61bf1
Added setup.py
kb1lqc Apr 30, 2017
ac7fbc2
Updated setup.py for Faraday
kb1lqc Apr 30, 2017
991dfcf
Updated setup.py to register with pypi
kb1lqc Apr 30, 2017
27c4649
Initial pypi files that sucessfully upload
kb1lqc Apr 30, 2017
6562a0f
Added requirements files
kb1lqc May 2, 2017
e2ea05f
Removed bad Proxy folder from packages list
kb1lqc May 3, 2017
c0d1def
Moved setup.py to setup.old.py for pbr
kb1lqc May 3, 2017
989bd4a
Minimal pbr setup.py
kb1lqc May 3, 2017
5f5cb97
Initial Faraday pbr configuration
kb1lqc May 3, 2017
b087fc9
pbr Based setup.cfg so far so good
kb1lqc May 3, 2017
5c96094
Fixed logging.ini import error
kb1lqc May 3, 2017
1d11677
Proxy.ini now imports
kb1lqc May 3, 2017
872db0e
WORKING FARADAY-PROXY AFTER PIP INSTALL!
kb1lqc May 3, 2017
7cb74e4
Initial faraday-telemetry command line working
kb1lqc May 3, 2017
89ba681
faraday-aprs working!
kb1lqc May 3, 2017
48ca3e0
faraday-simpleui now works!
kb1lqc May 3, 2017
f0196f1
Updated setup.cfg for correct file import in pbr
kb1lqc May 3, 2017
3cfb0eb
Added README
kb1lqc May 3, 2017
7428534
Updated setup.cfg to fix data_file
kb1lqc May 4, 2017
404b02f
Added updates for config file relative paths.
kb1lqc May 4, 2017
48323aa
Moved proxy.sample.ini to main project folder
kb1lqc May 6, 2017
c25bcb4
Moved proxy.sample.ini into a new etc/ folder
kb1lqc May 6, 2017
9f2dba2
Moved proxy files to etc
kb1lqc May 6, 2017
2b8f194
Added test.txt to create etc/faraday folder
kb1lqc May 6, 2017
3d35f34
Moved /etc files into /etc/faraday
kb1lqc May 6, 2017
e230a4f
Added updated proxy.py for /etc/faraday files
kb1lqc May 6, 2017
1584cee
Updated for dynamic config files
kb1lqc May 11, 2017
b975466
A working installable version of proxy
kb1lqc May 11, 2017
2e7955b
Working testmode and create folder tree for lib
kb1lqc May 11, 2017
326ee12
Fixed PEP8 Errors Per pytest
kb1lqc May 11, 2017
f470735
Updated configuration imports
kb1lqc May 28, 2017
50192b8
Successfully configured proxy from command line
kb1lqc May 28, 2017
ab7bac8
Updated configuration commands
kb1lqc May 29, 2017
29ed120
Updated proxy.py for PEP8
kb1lqc May 29, 2017
302315c
Updated configuration for second radio
kb1lqc May 29, 2017
e06e970
Started proxy section configuration
kb1lqc May 29, 2017
a09c006
Command line configuration of entire proxy config
kb1lqc May 29, 2017
50d3c76
Implemented Proxy log initialization
kb1lqc May 29, 2017
2646908
Added support for moving and showing logs
kb1lqc May 29, 2017
b6e8981
Updated docstrings for command line functions
kb1lqc May 29, 2017
a8451af
Updated userpath for config files and setup rev
kb1lqc May 29, 2017
b6798b4
Removed unneeded and failing argument line 215 proxy.py
Jun 18, 2017
cfd406c
Remove Unecessary setuptools options
kb1lqc Jun 18, 2017
8d72854
Update README with simple link to quickstart
kb1lqc Jun 18, 2017
e6e382f
Changed proxy.ini path to logger
kb1lqc Jun 18, 2017
01bf0bb
Removed unecessary path print and fixed logging
kb1lqc Jun 19, 2017
bf66c04
Removed unecesary argparse requirement
kb1lqc Jun 19, 2017
13746c0
Changed version in setup.cfg
kb1lqc Jun 19, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For installation instructions please visit https://github.com/FaradayRF/Faraday-Software/tree/master/Tutorials/start
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions faraday/aprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
import ConfigParser
import socket
import requests
import os
from time import sleep

# Start logging after importing modules
logging.config.fileConfig('loggingConfig.ini')
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'APRS', 'loggingConfig.ini')
logging.config.fileConfig(filename)
logger = logging.getLogger('APRS')

# Load Telemetry Configuration from telemetry.ini file
# Should have common file for apps...
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'APRS', 'aprs.ini')
aprsConfig = ConfigParser.RawConfigParser()
aprsConfig.read('aprs.ini')
aprsConfig.read(filename)

# Create and initialize dictionary queues
telemetryDicts = {}
Expand Down
226 changes: 219 additions & 7 deletions faraday/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,217 @@
import sys
import threading
import time
import argparse
import shutil

from flask import Flask
from flask import request

from faraday.uart import layer_4_service

# Start logging after importing modules
filename = os.path.abspath("loggingConfig.ini")
logging.config.fileConfig(filename)

relpath1 = os.path.join('etc', 'faraday')
relpath2 = os.path.join('..', 'etc', 'faraday')
setuppath = os.path.join(sys.prefix, 'etc', 'faraday')
userpath = os.path.join(os.path.expanduser('~'), '.faraday')
path = ''

for location in os.curdir, relpath1, relpath2, setuppath, userpath:
try:
logging.config.fileConfig(os.path.join(location, "loggingConfig.ini"))
path = location
break
except ConfigParser.NoSectionError:
pass
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I don't fail gracefully this code allows editable mode (or other installations) to fail if the file is never found. The code simply moves on with a blank path. Woops. This is related
to IT #206


logger = logging.getLogger('Proxy')

#Create Proxy configuration file path
proxyConfigPath = os.path.join(path, "proxy.ini")
logger.debug('Proxy.ini PATH: ' + proxyConfigPath)

# Command line input
parser = argparse.ArgumentParser(description='Proxy application interfaces a Faraday radio over USB UART')
parser.add_argument('--init-config', dest='init', action='store_true', help='Initialize Proxy configuration file')
parser.add_argument('--callsign', help='Set Faraday callsign')
parser.add_argument('--nodeid', type=int, help='Set Faraday node ID')
parser.add_argument('--port', help='Set Faraday UART port')
parser.add_argument('--baudrate', default='115200', help='Set Faraday UART baudrate')
parser.add_argument('--timeout', type=int, default=5, help='Set Faraday UART timeout')
parser.add_argument('--unit', type=int, default=0, help='Specify Faraday unit to configure')

#Proxy options
parser.add_argument('--number', type=int, default=0, help='Set number of Faraday radios to use')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be dangerous and/or not work. Keep an eye on this one. Might need to default to 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually OK. Defaulting to 0 basically keeps the 1 in the proxy.ini file until you specify something other than 0 or 1 (since 0 is ignored... you'd never have 0 units to startup. Maybe in testmode but that's getting in the weeds for now). Programming a number.

This does allow negative numbers and any number that is positive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK this is addressed in Issue #207

parser.add_argument('--log', action='store_true', help='Set Proxy into logging mode')
parser.add_argument('--test-mode', dest='testmode', action='store_true', help='Set Proxy into test mode')
parser.add_argument('--test-callsign', dest='testcallsign', help='Set Faraday test mode callsign')
parser.add_argument('--test-nodeid', dest='testnodeid', type=int, help='Set Faraday test mode nodeid')
parser.add_argument('--test-rate', dest='testrate', default=1, type=int, help='Set Faraday test mode rate')

# Proxy database options
parser.add_argument('--database', help='Set Faraday Proxy database')
parser.add_argument('--schema', help='Set Faraday database schema')
parser.add_argument('--test-database', dest='testdatabase', help='Set Faraday test mode database')
parser.add_argument('--init-log', dest='initlog', action='store_true', help='Initialize Proxy log database')
parser.add_argument('--save-log', dest='savelog', help='Save Proxy log database into new SAVELOG file')
parser.add_argument('--showlogs', action='store_true', help='Show Proxy log database files')

# Proxy Flask options
parser.add_argument('--flask-host', dest='flaskhost', help='Set Faraday Flask server host address')
parser.add_argument('--flask-port', type=int, dest='flaskport', help='Set Faraday Flask server port')

# Parse the arguments
args = parser.parse_args()


def initializeProxyConfig():
'''
Initialize proxy configuration file from proxy.sample.ini

:return: None, exits program
'''

logger.info("Initializing Proxy")
shutil.copy(os.path.join(path, "proxy.sample.ini"), os.path.join(path, "proxy.ini"))
logger.info("Initialization complete")
sys.exit(0)


def initializeProxyLog(config):
'''
Initialize the log database by deleting file

:param config: Proxy ConfigParser object from proxy.ini
:return: None
'''

logger.info("Initializing Proxy Log File")
log = config.get("DATABASE", "filename")
logpath = os.path.join(os.path.expanduser('~'), '.faraday', 'lib', log)
os.remove(logpath)
logger.info("Log initialization complete")


def saveProxyLog(name, config):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not work without pip install creating ~user/.faraday/lib

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applicable, folder created if not already existing whenever proxy is run:

https://github.com/FaradayRF/Faraday-Software/pull/203/files#diff-a9d2cba55827323291e9d0c49fd6f720R629

'''
Save proxy log database into a new file

:param name: Name of file to save data into (should be .db)
:param config: Proxy ConfigParser object from proxy.ini
:return: None
'''

log = config.get("DATABASE", "filename")
oldpath = os.path.join(os.path.expanduser('~'), '.faraday', 'lib', log)
newpath = os.path.join(os.path.expanduser('~'), '.faraday', 'lib', name)
shutil.move(oldpath, newpath)
sys.exit(0)


def showProxyLogs():
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not work without pip install creating ~user/.faraday/lib

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not applicable, folder created if not already existing whenever proxy is run:

https://github.com/FaradayRF/Faraday-Software/pull/203/files#diff-a9d2cba55827323291e9d0c49fd6f720R629

'''
Show proxy log database filenames in user path ~/.faraday/lib folder

:return: None, exits program
'''

logger.info("The following logs exist for Proxy...")
path = os.path.join(os.path.expanduser('~'), '.faraday', 'lib')
for file in os.listdir(path):
if file.endswith(".db"):
logger.info(file)
sys.exit(0)


def configureProxy(args, proxyConfigPath):
'''
Configure proxy configuration file from command line

:param args: argparse arguments
:param proxyConfigPath: Path to proxy.ini file
:return: None
'''

config = ConfigParser.RawConfigParser()
config.read(os.path.join(path, "proxy.ini"))

# Configure UNITx sections
unit = 'UNIT' + str(args.unit)
if args.unit is not 0:
try:
config.add_section(unit)

except ConfigParser.DuplicateSectionError:
pass

if args.callsign is not None:
config.set(unit, 'CALLSIGN', args.callsign)
if args.nodeid is not None:
config.set(unit, 'NODEID', args.nodeid)
if args.port is not None:
config.set(unit, 'COM', args.port)
if args.baudrate:
config.set(unit, 'BAUDRATE', args.baudrate)
if args.timeout:
config.set(unit, 'TIMEOUT', args.timeout)

# Configure Proxy section items
if args.number is not 0:
config.set('PROXY', 'units', args.number)
if args.log:
config.set('PROXY', 'log', 1)
else:
config.set('PROXY', 'log', 0)
if args.testmode:
config.set('PROXY', 'testmode', 1)
else:
config.set('PROXY', 'testmode', 0)
if args.testcallsign is not None:
config.set('PROXY', 'testcallsign', args.testcallsign)
if args.testnodeid is not None:
config.set('PROXY', 'testnodeid', args.testnodeid)
if args.testrate:
config.set('PROXY', 'testrate', args.testrate)

#Configure Proxy databases
if args.database is not None:
config.set('DATABASE', 'filename', args.database)
if args.schema is not None:
config.set('DATABASE', 'schemaname', args.schema)
if args.testdatabase is not None:
config.set('TESTDATABASE', 'filename', args.testdatabase)

# Configure Proxy flask server
if args.flaskhost is not None:
config.set('FLASK', 'host', args.flaskhost)
if args.flaskport is not None:
config.set('FLASK', 'port', args.flaskport)

with open(proxyConfigPath, 'wb') as configfile:
config.write(configfile)


# Initialize and configure proxy
if args.init:
initializeProxyConfig()
configureProxy(args, proxyConfigPath)

# Load Proxy Configuration from proxy.ini file
proxyConfig = ConfigParser.RawConfigParser()
filename = os.path.abspath("proxy.ini")
proxyConfig.read(filename)
proxyConfig.read(proxyConfigPath)

# Initialize Proxy log database
if args.initlog:
initializeProxyLog(proxyConfig)

# Save Proxy log database
if args.savelog is not None:
saveProxyLog(args.savelog, proxyConfig)

# List Proxy log database files
if args.showlogs:
showProxyLogs()

# Create and initialize dictionary queues
postDict = {}
Expand Down Expand Up @@ -427,11 +623,21 @@ def initDB():

:return: True or False if successful
"""
# make directory tree, necessary?
try:
os.makedirs(os.path.join(os.path.expanduser('~'), '.faraday.', 'lib'))
except:
pass

# Obtain configuration file names
# Obtain configuration file names, always place at sys.prefix
try:
dbFilename = proxyConfig.get("DATABASE", "FILENAME")
dbPath = os.path.join(os.path.expanduser('~'), '.faraday.', 'lib', dbFilename)
logger.debug("Proxy Database: " + dbPath)
dbFilename = dbPath

dbSchema = proxyConfig.get("DATABASE", "SCHEMANAME")
dbSchema = os.path.join(path, dbSchema)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down Expand Up @@ -468,6 +674,9 @@ def openTestDB():
# Obtain configuration file names
try:
testDbFilename = proxyConfig.get("TESTDATABASE", "FILENAME")
dbPath = os.path.join(os.path.expanduser('~'), '.faraday.', 'lib', testDbFilename)
logger.debug("Proxy Test Database: " + dbPath)
testDbFilename = dbPath

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down Expand Up @@ -523,7 +732,10 @@ def sqlInsert(data):

# Read in name of database
try:
db = proxyConfig.get("DATABASE", "FILENAME")
dbFilename = proxyConfig.get("DATABASE", "FILENAME")
dbPath = os.path.join(os.path.expanduser('~'), '.faraday.', 'lib', dbFilename)
logger.debug("Proxy Database: " + dbPath)
dbFilename = os.path.join(dbPath)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand All @@ -541,7 +753,7 @@ def sqlInsert(data):

# Connect to database, create SQL query, execute query, and close database
try:
conn = sqlite3.connect(db)
conn = sqlite3.connect(dbFilename)

except sqlite3.Error as e:
logger.error("Sqlite3.Error: " + str(e))
Expand Down
5 changes: 3 additions & 2 deletions faraday/simpleui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
from faraday.proxyio import gpioallocations

# Start logging after importing modules
filename = os.path.abspath("loggingConfig.ini")
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'SimpleUI', 'loggingConfig.ini')
filename = os.path.abspath(filename)
logging.config.fileConfig(filename)
logger = logging.getLogger('SimpleUI')

# Load configuration file
simpleuiconfig = ConfigParser.RawConfigParser()
filename = os.path.abspath("simpleui.ini")
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'SimpleUI', 'simpleui.ini')
simpleuiconfig.read(filename)

# Initialize Flask microframework
Expand Down
11 changes: 9 additions & 2 deletions faraday/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@

# Start logging after importing modules
try:
logging.config.fileConfig('loggingConfig.ini')
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', 'loggingConfig.ini')
logging.config.fileConfig(filename)
logger = logging.getLogger('telemetry')

except ConfigParser.Error as e:
Expand All @@ -38,7 +39,8 @@

# Load Telemetry Configuration from telemetry.ini file
telemetryConfig = ConfigParser.RawConfigParser()
telemetryFile = telemetryConfig.read('telemetry.ini')
filename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', 'telemetry.ini')
telemetryFile = telemetryConfig.read(filename)

if len(telemetryFile) == 0:
# File missing, indicate error and infinite loop
Expand Down Expand Up @@ -441,7 +443,9 @@ def initDB():
# Obtain configuration file names
try:
dbFilename = telemetryConfig.get("DATABASE", "FILENAME")
dbFilename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', dbFilename)
dbSchema = telemetryConfig.get("DATABASE", "SCHEMANAME")
dbSchema = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', dbSchema)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down Expand Up @@ -540,6 +544,7 @@ def sqlInsert(data):
# Read in name of telemetry database
try:
db = telemetryConfig.get("DATABASE", "FILENAME")
db = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', db)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down Expand Up @@ -651,6 +656,7 @@ def queryDb(parameters):
# Open configuration file
try:
dbFilename = telemetryConfig.get("DATABASE", "FILENAME")
dbFilename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', dbFilename)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down Expand Up @@ -755,6 +761,7 @@ def queryStationsDb(parameters):
# Get telemetry database name from configuration file
try:
dbFilename = telemetryConfig.get("DATABASE", "FILENAME")
dbFilename = os.path.join(os.path.dirname(__file__), '..', 'Applications', 'Telemetry', dbFilename)

except ConfigParser.Error as e:
logger.error("ConfigParse.Error: " + str(e))
Expand Down
Loading