summaryrefslogtreecommitdiff
path: root/contrib/mtn2git/mtn/common.py
diff options
context:
space:
mode:
authorKoen Kooi <koen@openembedded.org>2007-10-12 11:37:45 +0000
committerKoen Kooi <koen@openembedded.org>2007-10-12 11:37:45 +0000
commit1c5df3f485ba9992931e06d07f28c57a29d89e5e (patch)
treef1f786842f479fcdef015d6bfb430f8ea599fac1 /contrib/mtn2git/mtn/common.py
parentd6fd6d24ea9cef7d661bed9424f54a7719bea5dc (diff)
parent276e2ad3fd901d3fca0291979abc9c10455232ee (diff)
propagate from branch 'org.openembedded.dev' (head 7c2dfd8725acfc6de0286a17d58cccbfa6c141f8)
to branch 'org.openembedded.dev.avr32' (head 6a2246abf3d894c89fc60280e99b73072b879e02)
Diffstat (limited to 'contrib/mtn2git/mtn/common.py')
-rw-r--r--contrib/mtn2git/mtn/common.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/contrib/mtn2git/mtn/common.py b/contrib/mtn2git/mtn/common.py
new file mode 100644
index 0000000000..1bbf6031c9
--- /dev/null
+++ b/contrib/mtn2git/mtn/common.py
@@ -0,0 +1,49 @@
+
+import datetime
+import time
+import fcntl
+import os
+import signal
+import traceback
+import sys
+
+def parse_timecert(value):
+ return apply(datetime.datetime, time.strptime(value, "%Y-%m-%dT%H:%M:%S")[:6])
+
+def set_nonblocking(fd):
+ fl = fcntl.fcntl(fd, fcntl.F_GETFL)
+ fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
+
+def terminate_popen3(process):
+ print >> sys.stderr, ("[%s] stopping process: %s" % (os.getpid(), process.pid))
+ try:
+ process.tochild.close()
+ process.fromchild.close()
+ process.childerr.close()
+ if process.poll() == -1:
+ # the process is still running, so kill it.
+ os.kill(process.pid, signal.SIGKILL)
+ process.wait()
+ except:
+ print >> sys.stderr, ("%s failed_to_stop %s (%s)" % (os.getpid(), process.pid, traceback.format_exc()))
+
+def ago(event):
+ def plural(v, singular, plural):
+ if v == 1:
+ return "%d %s" % (v, singular)
+ else:
+ return "%d %s" % (v, plural)
+ now = datetime.datetime.utcnow()
+ ago = now - event
+ if ago.days > 0:
+ rv = "%s" % (plural(ago.days, "day", "days"))
+ elif ago.seconds > 3600:
+ hours = ago.seconds / 3600
+ minutes = (ago.seconds - (hours * 3600)) / 60
+ rv = "%s" % (plural(hours, "hour", "hours"))
+ else:
+ minutes = ago.seconds / 60
+ seconds = (ago.seconds - (minutes * 60))
+ rv = "%s" % (plural(minutes, "minute", "minutes"))
+ return rv
+