From 7bf087e64f0af1eca88e9fac45c991fd5f61fc46 Mon Sep 17 00:00:00 2001 From: trollhase Date: Mon, 23 Sep 2013 15:49:09 +0200 Subject: [PATCH] Zahlensysteme + modifikationen an deployserver und fakeftp --- deployserver.py | 3 +- fakeftp.py | 5 +++ zahlensysteme.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 zahlensysteme.py diff --git a/deployserver.py b/deployserver.py index 7f8d7f5..e3df44b 100644 --- a/deployserver.py +++ b/deployserver.py @@ -124,5 +124,6 @@ def deploy(port=1234,deploys=[],logger=NullLogger()): run(host="",port=port) deploy(deploys=[ - Deploy(key="foo",commands=[ExecCommand("touch fu.txt",shell=True)], cwd="/home/madmaurice/Public/") + Deploy(key="frontend",branch="master",commands=[ExecCommand("./deploy_master.sh",shell=True)]), + Deploy(key="frontend",branch="develop",commands=[ExecCommand("./deploy_develop.sh",shell=True)]) ],logger=FileLogger("deploy.log")) diff --git a/fakeftp.py b/fakeftp.py index aa7dcd8..afb518e 100644 --- a/fakeftp.py +++ b/fakeftp.py @@ -3,6 +3,7 @@ import threading import socket from random import randint import datetime + class Utils: @staticmethod def mask(rights): @@ -655,6 +656,8 @@ class LineReader: class FTPHandler(SocketServer.BaseRequestHandler): logger = StdoutLogger() + rootDirectory = Directory("") + authorizer = FailAuthorizer() def log(self, message): self.logger.log(self,message) @@ -729,6 +732,8 @@ class FTPHandler(SocketServer.BaseRequestHandler): self.log("Client disconnected") +#Sample configuration: + handler = FTPHandler handler.authorizer = AnonymousAuthorizer() diff --git a/zahlensysteme.py b/zahlensysteme.py new file mode 100644 index 0000000..2bdf45e --- /dev/null +++ b/zahlensysteme.py @@ -0,0 +1,84 @@ +class NumberException(Exception): + pass + +class NumericSystemException(Exception): + pass + +class Zahlensystem: + chars = map(str, range(0,10)) + map(chr, range(ord('A'), ord('F')+1)) + def __init__(self, basis): + self.basis = int(basis) + if self.basis > 16 or self.basis < 2: + raise NumberException("Numeric system %d is invalid" % (self.basis,)) + + def fromNum(self, num): + if type(num) != str: + num = str(num) + + if "." in num: + pre, post = num.split(".",2) + else: + pre = num + post = "" + + value = 0 + + for i,c in enumerate(pre): + e = (len(pre)-i-1) + try: + f = self.chars[:self.basis].index(c.upper()) + except ValueError: + raise NumberException("%d isn't a %d based number" % (f,self.basis)) + + value += f * self.basis**e + + for i,c in enumerate(post): + e = (-i-1) + try: + f = self.chars[:self.basis].index(c.upper()) + except ValueError: + raise NumberException("%d isn't a %d based number" % (f,self.basis)) + + value += f * self.basis**e + + return value + + def toNum(self, num): + num = float(num) + + if num < 0: + neg = True + num = -num + else: + neg = False + + pre, post = divmod(num, 1) + + v = "" + + if pre != 0: + n = pre + while n != 0: + n, r = divmod(n, self.basis) + v = self.chars[int(r)] + v + else: + v = "0" + + if post != 0: + v = v + "." + n = post + while n != 0: + r, n = divmod(n * self.basis, 1) + v = v + self.chars[int(r)] + + if neg: + v = "-" + v + + return v + +if __name__ == '__main__': + num = raw_input("Num> ") + fr = int(raw_input("From> ")) + to = int(raw_input("To> ")) + + print Zahlensystem(to).toNum(Zahlensystem(fr).fromNum(num)) \ No newline at end of file