forked from github/server
Merge branch 'master' into develop
This commit is contained in:
commit
89925bcd57
|
@ -60,28 +60,6 @@ writeheaders = True
|
||||||
# reject all html email?
|
# reject all html email?
|
||||||
rejecthtml = True
|
rejecthtml = True
|
||||||
|
|
||||||
def unlock_file(filename):
|
|
||||||
try:
|
|
||||||
os.unlink(filename+".lock")
|
|
||||||
except:
|
|
||||||
print "could not unlock %s.lock, file not found" % filename
|
|
||||||
|
|
||||||
def lock_file(filename):
|
|
||||||
i = 0
|
|
||||||
wait = 1
|
|
||||||
if not os.path.exists(filename):
|
|
||||||
file=open(filename, "w")
|
|
||||||
file.close()
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
os.symlink(filename, filename+".lock")
|
|
||||||
return
|
|
||||||
except:
|
|
||||||
i = i+1
|
|
||||||
if i == 5: unlock_file(filename)
|
|
||||||
sleep(wait)
|
|
||||||
wait = wait*2
|
|
||||||
|
|
||||||
messages = {
|
messages = {
|
||||||
"multipart-en" :
|
"multipart-en" :
|
||||||
"ERROR: The orders you sent contain no plaintext. " \
|
"ERROR: The orders you sent contain no plaintext. " \
|
||||||
|
@ -300,14 +278,12 @@ def accept(game, locale, stream, extend=None):
|
||||||
return -1
|
return -1
|
||||||
logger.info("received orders from " + email)
|
logger.info("received orders from " + email)
|
||||||
# get an available filename
|
# get an available filename
|
||||||
lock_file(gamedir + "/orders.queue")
|
|
||||||
maxdate, filename = available_file(savedir, prefix + email)
|
maxdate, filename = available_file(savedir, prefix + email)
|
||||||
if filename is None:
|
if filename is None:
|
||||||
logger.warning("more than " + str(maxfiles) + " orders from " + email)
|
logger.warning("more than " + str(maxfiles) + " orders from " + email)
|
||||||
return -1
|
return -1
|
||||||
# copy the orders to the file
|
# copy the orders to the file
|
||||||
text_ok = copy_orders(message, filename, email)
|
text_ok = copy_orders(message, filename, email)
|
||||||
unlock_file(gamedir + "/orders.queue")
|
|
||||||
|
|
||||||
warning, msg, fail = None, "", False
|
warning, msg, fail = None, "", False
|
||||||
maildate = message.get("Date")
|
maildate = message.get("Date")
|
||||||
|
@ -331,10 +307,8 @@ def accept(game, locale, stream, extend=None):
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
savedir = savedir + "/rejected"
|
savedir = savedir + "/rejected"
|
||||||
if not os.path.exists(savedir): os.mkdir(savedir)
|
if not os.path.exists(savedir): os.mkdir(savedir)
|
||||||
lock_file(gamedir + "/orders.queue")
|
|
||||||
maxdate, filename = available_file(savedir, prefix + email)
|
maxdate, filename = available_file(savedir, prefix + email)
|
||||||
store_message(message, filename)
|
store_message(message, filename)
|
||||||
unlock_file(gamedir + "/orders.queue")
|
|
||||||
fail = True
|
fail = True
|
||||||
|
|
||||||
if sendmail and warning is not None:
|
if sendmail and warning is not None:
|
||||||
|
@ -348,11 +322,9 @@ def accept(game, locale, stream, extend=None):
|
||||||
print filename
|
print filename
|
||||||
|
|
||||||
if not fail:
|
if not fail:
|
||||||
lock_file(gamedir + "/orders.queue")
|
|
||||||
queue = open(gamedir + "/orders.queue", "a")
|
queue = open(gamedir + "/orders.queue", "a")
|
||||||
queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game))
|
queue.write("email=%s file=%s locale=%s game=%s\n" % (email, filename, locale, game))
|
||||||
queue.close()
|
queue.close()
|
||||||
unlock_file(gamedir + "/orders.queue")
|
|
||||||
|
|
||||||
logger.info("done - accepted orders from " + email)
|
logger.info("done - accepted orders from " + email)
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,16 @@ if [ ! -d backup ] ; then
|
||||||
ln -sf ~/backup/eressea/game-$GAME backup
|
ln -sf ~/backup/eressea/game-$GAME backup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -e reports/reports.txt ] ; then
|
||||||
|
echo "backup reports $TURN, game $GAME"
|
||||||
|
tar cjf backup/$TURN-reports.tar.bz2 reports
|
||||||
|
curl -s -n -T backup/$TURN-reports.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN-reports.tar.bz2
|
||||||
|
fi
|
||||||
files="data/$TURN.dat parteien.full parteien"
|
files="data/$TURN.dat parteien.full parteien"
|
||||||
if [ -e orders.$TURN ]; then
|
if [ -e orders.$TURN ]; then
|
||||||
files="$files orders.$TURN"
|
files="$files orders.$TURN"
|
||||||
fi
|
fi
|
||||||
echo "backup turn $TURN, game $GAME, files: $files"
|
echo "backup turn $TURN, game $GAME, files: $files"
|
||||||
if [ -d reports ] ; then
|
|
||||||
tar cjf backup/$TURN-reports.tar.bz2 reports
|
|
||||||
fi
|
|
||||||
tar cjf backup/$TURN.tar.bz2 $files
|
tar cjf backup/$TURN.tar.bz2 $files
|
||||||
echo "uploading game-$GAME/$TURN.tar.bz2"
|
|
||||||
curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2
|
curl -s -n -T backup/$TURN.tar.bz2 https://dav.box.com/dav/Eressea/game-$GAME/$TURN.tar.bz2
|
||||||
#curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db
|
#curl -s -n -T eressea.db https://dav.box.com/dav/Eressea/eressea.db
|
||||||
|
|
|
@ -19,30 +19,21 @@ mkdir $REPORTS
|
||||||
|
|
||||||
cd $ERESSEA/game-$GAME
|
cd $ERESSEA/game-$GAME
|
||||||
|
|
||||||
# wait for the queue lock to go away
|
|
||||||
maxt=5
|
|
||||||
to=5
|
|
||||||
while [ -e orders.queue.lock ] ; do
|
|
||||||
echo "waiting for orders to finish processing."
|
|
||||||
sleep $to
|
|
||||||
let to=$to+$to
|
|
||||||
let mast=$maxt-1
|
|
||||||
[ $maxt -lt 0 ] && break
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -d test ]; then
|
if [ -d test ]; then
|
||||||
touch test/execute.lock
|
touch test/execute.lock
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$BIN/create-orders $GAME $TURN
|
$BIN/create-orders $GAME $TURN
|
||||||
|
if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then
|
||||||
|
echo "server did not create orders for turn $TURN in game $GAME"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
$BIN/backup-eressea $GAME $TURN
|
$BIN/backup-eressea $GAME $TURN
|
||||||
rm -f execute.lock
|
rm -f execute.lock
|
||||||
$BIN/run-turn $GAME $TURN
|
$BIN/run-turn $GAME $TURN
|
||||||
touch execute.lock
|
touch execute.lock
|
||||||
|
|
||||||
if [ ! -s $ERESSEA/game-$GAME/orders.$TURN ]; then
|
|
||||||
echo "server did not create orders for turn $TURN in game $GAME"
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
if [ ! -s $REPORTS/reports.txt ]; then
|
if [ ! -s $REPORTS/reports.txt ]; then
|
||||||
echo "server did not create reports.txt in game $GAME"
|
echo "server did not create reports.txt in game $GAME"
|
||||||
exit 4
|
exit 4
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
SCRIPT=$(readlink -f $0)
|
SCRIPT=$(readlink -f $0)
|
||||||
cd $(dirname $SCRIPT)
|
cd $(dirname $SCRIPT)
|
||||||
python accept-orders.py "$@"
|
|
||||||
|
lockfile -r3 -l120 orders.queue.lock
|
||||||
|
python accept-orders.py "$@"
|
||||||
|
rm -f orders.queue.lock
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
SCRIPT=$(readlink -f $0)
|
SCRIPT=$(readlink -f $0)
|
||||||
cd $(dirname $SCRIPT)
|
cd $(dirname $SCRIPT)
|
||||||
python process-orders.py "$@"
|
|
||||||
|
|
||||||
|
lockfile -r3 -l120 orders.queue.lock
|
||||||
|
python process-orders.py "$@"
|
||||||
|
rm -f orders.queue.lock
|
||||||
|
|
|
@ -21,29 +21,6 @@ def pwd_get_email(faction, pwd, pwdfile=None):
|
||||||
def split_filename(filename):
|
def split_filename(filename):
|
||||||
return os.path.split(filename)
|
return os.path.split(filename)
|
||||||
|
|
||||||
def unlock_file(filename):
|
|
||||||
try:
|
|
||||||
unlink(filename+".lock")
|
|
||||||
except:
|
|
||||||
print "could not unlock %s.lock, file not found" % filename
|
|
||||||
raise
|
|
||||||
|
|
||||||
def lock_file(filename):
|
|
||||||
i = 0
|
|
||||||
wait = 1
|
|
||||||
if not os.path.exists(filename):
|
|
||||||
file=open(filename, "w")
|
|
||||||
file.close()
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
symlink(filename, filename+".lock")
|
|
||||||
return
|
|
||||||
except:
|
|
||||||
i = i+1
|
|
||||||
if i == 5:
|
|
||||||
raise
|
|
||||||
sleep(wait)
|
|
||||||
wait = wait*2
|
|
||||||
|
|
||||||
messages = {
|
messages = {
|
||||||
"subject-de": "Befehle angekommen",
|
"subject-de": "Befehle angekommen",
|
||||||
|
@ -133,16 +110,12 @@ def echeck(filename, locale, rules):
|
||||||
#print "reading password file..."
|
#print "reading password file..."
|
||||||
pw_data = EPasswd()
|
pw_data = EPasswd()
|
||||||
try:
|
try:
|
||||||
pw_data.load_database(os.path.join(game_dir,"eressea.db"))
|
pw_data.load_database(os.path.join(game_dir, "eressea.db"))
|
||||||
except:
|
except:
|
||||||
pw_data.load_file(os.path.join(game_dir,"passwd"))
|
pw_data.load_file(os.path.join(game_dir, "passwd"))
|
||||||
|
|
||||||
#print "reading orders.queue..."
|
#print "reading orders.queue..."
|
||||||
# move the queue file to a save space while locking it:
|
# move the queue file to a safe space while locking it:
|
||||||
try:
|
|
||||||
lock_file(queue_file)
|
|
||||||
except:
|
|
||||||
exit(0)
|
|
||||||
queuefile = open(queue_file, "r")
|
queuefile = open(queue_file, "r")
|
||||||
lines = queuefile.readlines()
|
lines = queuefile.readlines()
|
||||||
queuefile.close()
|
queuefile.close()
|
||||||
|
@ -150,22 +123,13 @@ queuefile.close()
|
||||||
# copy to a temp file
|
# copy to a temp file
|
||||||
|
|
||||||
tname="/tmp/orders.queue.%s" % str(time())
|
tname="/tmp/orders.queue.%s" % str(time())
|
||||||
try:
|
|
||||||
lock_file(tname)
|
|
||||||
except:
|
|
||||||
exit(0)
|
|
||||||
tmpfile=open(tname, "w")
|
tmpfile=open(tname, "w")
|
||||||
for line in lines:
|
for line in lines:
|
||||||
tmpfile.write(line)
|
tmpfile.write(line)
|
||||||
tmpfile.close()
|
tmpfile.close()
|
||||||
|
|
||||||
openlog("orders")
|
openlog("orders")
|
||||||
|
|
||||||
unlink(queue_file)
|
unlink(queue_file)
|
||||||
try:
|
|
||||||
unlock_file(queue_file)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
tokens = split(line[:-1], ' ')
|
tokens = split(line[:-1], ' ')
|
||||||
|
@ -193,7 +157,7 @@ for line in lines:
|
||||||
if success: failed = False
|
if success: failed = False
|
||||||
else: msg = msg + messages["unknown-"+locale] + "\n"
|
else: msg = msg + messages["unknown-"+locale] + "\n"
|
||||||
msg = msg + "\n"
|
msg = msg + "\n"
|
||||||
logfile.write("%s:%s:%s:%s:%s:%s\n" % (ctime(time()), email, game_email, faction, pwd, success))
|
logfile.write("%s:%s:%s:%s:%s\n" % (ctime(time()), email, game_email, faction, success))
|
||||||
logfile.close()
|
logfile.close()
|
||||||
|
|
||||||
if failed:
|
if failed:
|
||||||
|
@ -221,4 +185,3 @@ for line in lines:
|
||||||
|
|
||||||
closelog()
|
closelog()
|
||||||
unlink(tname)
|
unlink(tname)
|
||||||
unlock_file(tname)
|
|
||||||
|
|
Loading…
Reference in New Issue