3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-30 14:49:28 +01:00

pylink: implement --version, --no-pid

Closes #242.
This commit is contained in:
James Lu 2016-06-21 11:03:28 -07:00
parent cb633cfba5
commit 75ae50e03a

11
pylink
View File

@ -3,9 +3,9 @@
import os import os
import sys import sys
try: try:
from pylinkirc import conf from pylinkirc import world, conf
except ImportError: except ImportError:
sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.conf).\n\nIf you are " sys.stderr.write("ERROR: Failed to import PyLink main module (pylinkirc.world).\n\nIf you are "
"running PyLink from source, please install PyLink first using 'python3 " "running PyLink from source, please install PyLink first using 'python3 "
"setup.py install [--user]'\n") "setup.py install [--user]'\n")
sys.exit(1) sys.exit(1)
@ -19,6 +19,10 @@ if __name__ == '__main__':
parser.add_argument("-n", "--no-pid", help="skips generating PID files", action='store_true') parser.add_argument("-n", "--no-pid", help="skips generating PID files", action='store_true')
args = parser.parse_args() args = parser.parse_args()
if args.version: # Display version and exit
print(world.version)
sys.exit()
# Load the config # Load the config
conf.loadConf(args.config) conf.loadConf(args.config)
@ -26,7 +30,8 @@ if __name__ == '__main__':
from pylinkirc import classes, utils, coreplugin, world from pylinkirc import classes, utils, coreplugin, world
log.info('PyLink %s starting...', world.version) log.info('PyLink %s starting...', world.version)
# Write a PID file. # Write a PID file unless specifically told not to.
if not args.no_pid:
with open('%s.pid' % conf.confname, 'w') as f: with open('%s.pid' % conf.confname, 'w') as f:
f.write(str(os.getpid())) f.write(str(os.getpid()))