Skip to content

Commit 417db1c

Browse files
authored
Merge pull request #1 from christian-intra2net/apple-zip-files
Apple zip files
2 parents 91d9d99 + 208ffff commit 417db1c

File tree

5 files changed

+88
-53
lines changed

5 files changed

+88
-53
lines changed

db/AppleDouble/AppleDouble

406 Bytes
Binary file not shown.

db/AppleDouble/AppleDouble.source.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
AUTHOR: Intra2net <[email protected]>
2+
URL: Created it myself
3+
LICENSE: public domain
4+
NOTE: AppleDouble files appear in folder __MACOSX of zip files created on MacOSX systems with same name and path as the "real" zip file contents

db/DS_Store/DS_Store

6 KB
Binary file not shown.

db/DS_Store/DS_Store.source.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
AUTHOR: Intra2net <[email protected]>
2+
URL: Created it myself
3+
LICENSE: public domain

review-patch.py

Lines changed: 81 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,74 +21,102 @@
2121
import sys
2222

2323
def review_patches(patches):
24-
ret = 0
25-
for patch in patches:
26-
out = ""
27-
f = open(patch)
24+
ret = 0
25+
for patch in patches:
26+
out = ""
27+
f = open(patch)
2828

29-
added_files = []
30-
files_without_source = []
29+
added_files = []
30+
files_without_source = []
3131

32-
for line in f.readlines():
33-
filename = ""
34-
if line.startswith("+++"):
35-
filename = line[4:-1]
36-
elif line.startswith("diff --git"):
37-
filename = line[line.rfind(" ") + 1:-1]
32+
for line in f.readlines():
33+
filename = ""
34+
if line.startswith("+++"):
35+
filename = line[4:-1]
36+
elif line.startswith("diff --git"):
37+
filename = line[line.rfind(" ") + 1:-1]
3838

39-
if filename != "" and not filename in added_files:
40-
added_files.append(filename)
41-
if not filename.endswith(".source.txt"):
42-
files_without_source.append(filename)
43-
f.close()
39+
if filename != "" and not filename in added_files:
40+
added_files.append(filename)
41+
if not filename.endswith(".source.txt"):
42+
files_without_source.append(filename)
43+
f.close()
4444

4545

46-
local_error = False
46+
local_error = False
4747

48-
added_files.sort()
49-
for f in added_files:
50-
dir_id = f.rfind("/") + 1
51-
ext_id = dir_id + f[dir_id:].find(".")
52-
if ext_id != -1:
53-
ext = f[ext_id + 1:]
54-
if ext.endswith("source.txt"):
55-
real_db_file = f[:-len(".source.txt")]
56-
try:
57-
files_without_source.remove(real_db_file)
58-
except:
59-
out += "\t" + f + ": .source.txt found for non-existing file, expecting " + real_db_file + " in patch\n"
60-
ret = 1
61-
local_error = True
62-
else:
63-
db_dir = os.path.basename(os.path.dirname(f))
64-
if db_dir != ext:
65-
out += "\t" + f + ": File is not in proper directory according to extension\n"
66-
ret = 1
67-
local_error = True
48+
added_files.sort()
49+
for f in added_files:
50+
dir_id = f.rfind("/") + 1 # f[dir_id:] is name.type[.source.txt]
51+
if dir_id == 0:
52+
out += "\tMalformed patch: " + f + " should be of the form 'b/db/type/name.type[.source.txt]'\n"
53+
ret = 1
54+
local_error = True
55+
continue
56+
if not "/db/" in f:
57+
continue # file is not in db subdir
6858

69-
for f in files_without_source:
70-
out += "\t" + f + ": Does not have matching .source.txt file with license\n"
71-
ret = 1
72-
local_error = True
59+
ext_id = dir_id + f[dir_id:].find(".")
60+
if ext_id == dir_id-1: # check if f is .../db/type/type or .../db/misc/type
61+
dir_id2 = f.rfind("/", 0, dir_id-1)+1 # f[dir_id2:dir_id] is subdir within db/
62+
if f[dir_id2:dir_id-1] == f[dir_id:]:
63+
pass # ok, is .../db/type/type
64+
if f[dir_id2] in ('.', '_'):
65+
out += "\t" + f + ": Subdir names may not start with . or _\n"
66+
ret = 1
67+
local_error = True
68+
elif f[dir_id2:dir_id-1] == 'misc':
69+
pass # ok, is .../db/msic/type
70+
else:
71+
out += "\t" + f + ": File is not in proper directory according to extension\n"
72+
ret = 1
73+
local_error = True
74+
else:
75+
ext = f[ext_id + 1:] # ext is type[.source.txt]
76+
if ext.endswith("source.txt"):
77+
real_db_file = f[:-len(".source.txt")]
78+
try:
79+
files_without_source.remove(real_db_file)
80+
except:
81+
out += "\t" + f + ": .source.txt found for non-existing file, expecting " + real_db_file + " in patch\n"
82+
ret = 1
83+
local_error = True
84+
else:
85+
db_dir = os.path.basename(os.path.dirname(f))
86+
if db_dir != ext:
87+
out += "\t" + f + ": File is not in proper directory according to extension\n"
88+
ret = 1
89+
local_error = True
7390

74-
if local_error:
75-
print "Patch", patch + ":"
76-
print out
91+
for f in files_without_source:
92+
out += "\t" + f + ": Does not have matching .source.txt file with license\n"
93+
ret = 1
94+
local_error = True
7795

78-
return ret
96+
if local_error:
97+
print "Patch", patch + ":"
98+
print out
99+
100+
return ret
79101

80102
if __name__ == '__main__':
81-
if len(sys.argv) == 1:
82-
print "Reviews patches for file-tests database."
83-
print """There are following rules currently:
103+
if len(sys.argv) == 1:
104+
print "Reviews patches for file-tests database."
105+
print """There are following rules currently:
84106
- Every file 'F' in file-tests database has to have matching 'F.source.txt'
85107
file with the license information. Note that case sensitivity is important
86108
and must be respected.
87109
- Every file with extension '.X' has to be in directory 'db/X' according to
88110
its extension. Note that case sensitivity is important and must be
89111
respected.
112+
- If a file has no (typical) extension (e.g. AppleDouble), then it has to go
113+
to folder db/misc or must be given a descriptive short name and no extension
114+
and appear in a directory of the same name (e.g. db/AppleDouble/AppleDouble).
115+
The corresponding .source.txt needs to explain this in a line starting with
116+
'NOTE: ' (see e.g. db/AppleDouble/AppleDouble.source.txt). No leading . or _
117+
(e.g. .DS_Store --> DS_Store)
90118
"""
91-
print "Usage: " + sys.argv[0] + " [[patch1], [patch2], ...]"
92-
print "Usage: " + sys.argv[0] + " *.patch"
93-
sys.exit(0)
94-
sys.exit(review_patches(sys.argv[1:]))
119+
print "Usage: " + sys.argv[0] + " [[patch1], [patch2], ...]"
120+
print "Usage: " + sys.argv[0] + " *.patch"
121+
sys.exit(0)
122+
sys.exit(review_patches(sys.argv[1:]))

0 commit comments

Comments
 (0)