-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathutils.py
More file actions
39 lines (31 loc) · 1 KB
/
utils.py
File metadata and controls
39 lines (31 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
import time, datetime
import os
iso6709 = re.compile(r'((\+|-)[0-9]*.[0-9]*)((\+|-)[0-9]*.[0-9]*)')
def decodeIso6709(strLoc):
match = iso6709.fullmatch(strLoc)
return (float(match.group(1)), float(match.group(3)))
def currentPosixTime():
d = datetime.datetime.now()
return time.mktime(d.timetuple())
def floatToStr(f, plus=False):
if f >= 0:
return ('+' if plus else '') + str(f)
else:
return str(f)
def keywordString(keywords):
pieces = []
for keyword in keywords:
pieces.append(keyword + '=' + keywords[keyword])
return '&'.join(pieces)
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)