-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcserver-motd
53 lines (41 loc) · 1.24 KB
/
mcserver-motd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# Author : Phidica Veia
# Create : 2015-10-01
# This is a support script for the mcserver Bash script. If you want to though, you can make it executable with "chmod +x mcserver-motd" and use it as described in the usage
import sys, getopt
from pyjavaproperties import Properties
def showUsage():
print "Usage: mcserver-motd <infile.properties> -g"
print " or: mcserver-motd <infile.properties> -s <\"new message\">"
print "For the given file, get the current MotD or set a new one"
def main(infile, argv):
if len(argv) == 0:
showUsage()
sys.exit(2)
try:
opts, args = getopt.getopt(argv, "hgs:")
except getopt.GetoptError:
showUsage()
sys.exit(2)
try:
p = Properties()
p.load(open(infile))
except IOError as detail:
sys.exit( "{} {}".format("mcserver-motd error:", detail) )
for opt, arg in opts:
if opt == "-g":
print p["motd"]
elif opt == "-s":
p["motd"] = arg
elif opt == "-h":
showUsage()
p.store(open(infile,"w"))
# Read the infile from the arguments, if possible
try:
infile = sys.argv[1]
except IndexError:
showUsage()
sys.exit(2)
# Operate on the infile using all subsequent arguments
if __name__ == "__main__":
main(infile, sys.argv[2:])