Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Commit

Permalink
added ability to change configuration with yaml config file
Browse files Browse the repository at this point in the history
  • Loading branch information
David Whiteside committed Nov 28, 2016
1 parent 0b531da commit c250cf2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ python:

# Install Dependencies
install:
- pip install nose coveralls
- pip install nose coveralls PyYAML

# Run Tests
script:
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ n021 | 2016-11-26 19:00:01 | offline,down | 'DIMM Configuration Error'
-- --
```

Use --help to show all options.
You can setup the configuration file for tracknodes to change the database location or the command to get node status. Use the below as an example.

```shell
$ cat /etc/tracknodes.conf
---
dbfile: "/opt/tracknodes.db"
pbsnodes_cmd: "/opt/pbsnodes"
```

```shell
$ tracknodes --help
Expand Down
16 changes: 15 additions & 1 deletion lib/tracknodes/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
""" Command Line Interface Module """
import optparse
import os
import yaml
from tracknodes import TrackNodes


Expand All @@ -21,7 +23,7 @@ def __init__(self):
parser.add_option("-c", "--pbsnodes_cmd", dest="pbsnodes_cmd",
help="pbsnodes binary location, example: /opt/pbsnodes",
metavar="PBSNODESCMD",
default="pbsnodes")
default=None)
parser.add_option("-v", "--verbose", dest="verbose",
help="Verbose Output",
metavar="VERBOSE",
Expand All @@ -33,6 +35,18 @@ def __init__(self):
self.dbfile = options.dbfile
self.verbose = options.verbose

# Load Configurations if not set on CLI
if os.path.isfile('/etc/tracknodes.conf'):
with open('/etc/tracknodes.conf', 'r') as f:
tracknodes_conf = yaml.load(f)
if tracknodes_conf is not None:
if "dbfile" in tracknodes_conf:
if self.dbfile is None:
self.dbfile = str(tracknodes_conf["dbfile"])
if "pbsnodes_cmd" in tracknodes_conf:
if self.pbsnodes_cmd is None:
self.pbsnodes_cmd = str(tracknodes_conf["pbsnodes_cmd"])

def run(self):
""" EntryPoint Of Application """
pbsnodes = TrackNodes(update=self.update, dbfile=self.dbfile, pbsnodes_cmd=self.pbsnodes_cmd, verbose=self.verbose)
Expand Down
3 changes: 3 additions & 0 deletions lib/tracknodes/tracknodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def is_exe(fpath):
""" File must have execute bit set """
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

if program is None:
return None

fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author_email='[email protected]',
url='https://github.com/NREL/tracknodes',
license='GPL',
install_requires=[],
install_requires=["PyYAML"],
package_dir={
'': 'lib'},
packages=find_packages('lib'),
Expand Down

0 comments on commit c250cf2

Please sign in to comment.