]>
Commit | Line | Data |
---|---|---|
e853a9d4 | 1 | #!/usr/bin/env python |
2 | ||
3b7a53b6 | 3 | # Copyright (c) 2007, Intel Corporation |
4 | # All rights reserved. This program and the accompanying materials | |
5 | # are licensed and made available under the terms and conditions of the BSD License | |
6 | # which accompanies this distribution. The full text of the license may be found at | |
7 | # http://opensource.org/licenses/bsd-license.php | |
8 | # | |
9 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
10 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
11 | ||
e853a9d4 | 12 | import os, sys, re, getopt, string, glob, xml.dom.minidom, pprint, md5, socket, getpass, time, random |
13 | ||
14 | def inWorkspace(rel_path=""): | |
15 | """Treat the given path as relative to the workspace.""" | |
16 | ||
17 | # Make sure the user has set the workspace variable: | |
18 | try: | |
19 | return os.path.join(os.environ["WORKSPACE"], rel_path ) | |
20 | except: | |
21 | print "Oops! You must set the WORKSPACE environment variable to run this script." | |
22 | sys.exit() | |
23 | ||
24 | def genguid(): | |
25 | g = md5.md5( | |
26 | str(random.random()) + | |
27 | getpass.getuser() + | |
28 | str(time.time()) + | |
29 | socket.gethostbyname(socket.gethostname())).hexdigest() | |
822d4f3a | 30 | return Guid("%s-%s-%s-%s-%s" % (g[0:8], g[8:12], g[12:16], g[16:20], g[20:])) |
af2efcaf | 31 | |
32 | def lean(path): | |
33 | """Lean the slashes forward""" | |
34 | ||
35 | return os.path.normpath(path).replace("\\", "/") | |
4040421a | 36 | |
37 | def mkdir(path): | |
38 | """Make a directory if it is not there already.""" | |
39 | ||
40 | try: | |
41 | os.makedirs(path) | |
42 | except: | |
43 | pass | |
44 | ||
312ffece | 45 | def Md5(filename): |
46 | ||
47 | sum = "" | |
48 | ||
49 | try: | |
50 | f=open(filename, "rb") | |
51 | sum = md5.md5(f.read()).hexdigest() | |
52 | f.close() | |
53 | except IOError: | |
54 | print "Error: Unable to open file: %s" % filename | |
55 | sys.exit() | |
56 | ||
57 | return sum | |
58 | ||
822d4f3a | 59 | def Guid(guidString): |
60 | """Convert the guid string into a canonical form suitable for comparison.""" | |
61 | return string.lower(guidString) |