forked from mason-bially/windows-installer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlocal_utils.py
41 lines (27 loc) · 862 Bytes
/
local_utils.py
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
40
#Ultils to scan local files for Version Information
#@Clark Rinker, June 2012
#@Western Washington University
import re
import _winreg as winkey #Bad? More like that underscore is bad
testPath="C:\\Python27\\README.txt"
vRegex="[0-9]+(?:\.[0-9]+)*"
class AmbiguousMatchError(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return repr(self.value)
class NoMatchError(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return repr(self.value)
def findVersionInFile(fileString,pattern):
s=open(fileString()).read()
matches=re.findall(pattern,s)
if len(matches)==0:
raise NoMatchError
if len(matches>1):
raise AmbiguousMatchError
else:
return matches[0]
#def test():