Browse Source

Adds new parameter '--report-store' to specify the path at which received reports will get stored.

The parameter is optional and if unset, a directory named 'reports' will get
created inside the directoy in which the 'server.py' file resides.

Signed-off-by: Stefan Laudemann <thisco@zitmail.uni-paderborn.de>
Stefan Laudemann 9 years ago
parent
commit
1c3a7f492c
1 changed files with 16 additions and 6 deletions
  1. 16 6
      server.py

+ 16 - 6
server.py

@@ -8,11 +8,13 @@ import daemon.pidlockfile
 import traceback
 import os
 
+BUFFER_SIZE = 4096
+
 def myrandom(length):
    return ''.join(random.choice(string.lowercase) for i in range(length))
 
-def serve(port, bindTo):
-	BUFFER_SIZE = 1024
+def serve(port, bindTo, path_report_store=None):
+	assert path_report_store != None
  
 	s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
 	s.settimeout(30.0)
@@ -24,7 +26,9 @@ def serve(port, bindTo):
 		conn, addr = s.accept()
 
 		report_id = myrandom(10)
-		filename = '/opt/debugserver/reports/' + datetime.date.today().strftime('%Y-%m-%d_') + report_id + '.gz'
+		filename = os.path.join(
+			path_report_store, "%s_%s.log" % (report_id, datetime.date.today().strftime('%Y-%m-%d_'))
+		)
 
 		with open(filename, 'w') as f:
 			try:
@@ -61,7 +65,7 @@ def serve(port, bindTo):
 
 if __name__ == '__main__':
 	try: 
-		opts, args = getopt.getopt(sys.argv[1:], "dp:b:", ["daemonize", "port=", "bind-to="])
+		opts, args = getopt.getopt(sys.argv[1:], "dp:b:s:", ["daemonize", "port=", "bind-to=", "report-store="])
 	except:
 		print ('Unrecognized option')
 		sys.exit(2)
@@ -69,6 +73,7 @@ if __name__ == '__main__':
 	daemonize = False
 	port = 1337
 	bindTo = None
+	path_report_store = os.path.join(os.path.dirname(sys.argv[0]), "reports")
 
 	for opt, arg in opts:
 		if opt in ("-d", "--daemonize"):
@@ -82,6 +87,8 @@ if __name__ == '__main__':
 			except:
 				traceback.print_exc()
 				sys.exit(1)
+		elif opt in ("-s", "--report-store"):
+			path_report_store = arg
 		else:
 			assert False
 	
@@ -89,9 +96,12 @@ if __name__ == '__main__':
 		print("Listening IP address is unset. Using default ::")
 		bindTo = "::"
 
+	if not os.path.exists(path_report_store):
+		os.makedirs(path_report_store)
+
 	if daemonize == True:
 		daemonContext = daemon.DaemonContext(pidfile = daemon.pidlockfile.PIDLockFile("/var/run/ffpb-debugserver.pid"))
 		with daemonContext:
-			serve(port, bindTo)		
+			serve(port, bindTo, path_report_store=path_report_store)
 	else:
-		serve(port, bindTo)
+		serve(port, bindTo, path_report_store=path_report_store)