forked from steffi7574/LayerParallelLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
84 lines (65 loc) · 2.17 KB
/
Copy pathutil.py
File metadata and controls
84 lines (65 loc) · 2.17 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
import os
import string
import shutil, glob
def make_link(src,dst):
""" make_link(src,dst)
makes a relative link
Inputs:
src - source file
dst - destination to place link
"""
assert os.path.exists(src) , 'source file does not exist \n%s' % src
# find real file, incase source itself is a link
src = os.path.realpath(src)
# normalize paths
src = os.path.normpath(src)
dst = os.path.normpath(dst)
# check for self referencing
if src == dst: return
# find relative folder path
srcfolder = os.path.join( os.path.split(src)[0] ) + '/'
dstfolder = os.path.join( os.path.split(dst)[0] ) + '/'
srcfolder = os.path.relpath(srcfolder,dstfolder)
src = os.path.join( srcfolder, os.path.split(src)[1] )
# make unix link
if os.path.exists(dst): os.remove(dst)
os.symlink(src,dst)
def comparefiles(refname, testname):
""" comparefiles(refname, testname)
compares the two files line by line
ignoring last element in each line
ignoring lines that start with '#'
Inputs:
refname - reference filename
testname - filename to compare
Output:
boolean indicating equal files (0) or differing files (1)
"""
# open the files
reffile = open(refname, 'r')
testfile = open(testname, 'r')
# count the different elements
fail = 0
# loop over all lines
for refline in reffile:
# read the line in the testfile
testline = testfile.readline()
if not testline:
fail = 1
break
# split lines into elements (space delimiter)
refwords = string.split(refline, ' ')
testwords = string.split(testline, ' ')
# ignore lines that start with '#'
if refwords[0] == '#':
continue
# loop over all but the last elements
for ref, test in zip(refwords[:-1], testwords[:-1]):
if ref != test :
fail = 1
break
# close the files
reffile.close()
testfile.close()
return fail