Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Don't break when sizes or durations are given as integers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Haines committed Apr 30, 2015
1 parent c28f1d1 commit 74aaacf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions demo/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ for port in 8080 8081 8082; do

https_port=$((port + 400))
mkdir -p demo/$port
pushd demo/$port
# pushd demo/$port

rm $DIR/etc/$port.config
#rm $DIR/etc/$port.config
python -m synapse.app.homeserver \
--generate-config \
-H "localhost:$https_port" \
Expand All @@ -39,7 +39,7 @@ for port in 8080 8081 8082; do
-D \
-vv \

popd
# popd
done

cd "$CWD"
21 changes: 12 additions & 9 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,33 @@ class ConfigError(Exception):
class Config(object):

@staticmethod
def parse_size(string):
def parse_size(value):
if isinstance(value, int) or isinstance(value, long):
return value
sizes = {"K": 1024, "M": 1024 * 1024}
size = 1
suffix = string[-1]
suffix = value[-1]
if suffix in sizes:
string = string[:-1]
value = value[:-1]
size = sizes[suffix]
return int(string) * size
return int(value) * size

@staticmethod
def parse_duration(string):
def parse_duration(value):
if isinstance(value, int) or isinstance(value, long):
return value
second = 1000
hour = 60 * 60 * second
day = 24 * hour
week = 7 * day
year = 365 * day

sizes = {"s": second, "h": hour, "d": day, "w": week, "y": year}
size = 1
suffix = string[-1]
suffix = value[-1]
if suffix in sizes:
string = string[:-1]
value = value[:-1]
size = sizes[suffix]
return int(string) * size
return int(value) * size

@staticmethod
def abspath(file_path):
Expand Down

0 comments on commit 74aaacf

Please sign in to comment.