Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ endif
all: $(BINARIES)

$(HOOKSRC): $(SIGS) $(FLAGS) $(JINJA2) $(HOOKREQ) $(YAML)
python2 utils/process.py $(RELMODE) --apis=$(APIS)
python utils/process.py $(RELMODE) --apis=$(APIS)

$(INSNSSRC) $(FLAGSRC): $(HOOKSRC)

Expand Down
6 changes: 3 additions & 3 deletions test/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __getattr__(self, name):

def compile_file(fname, arch):
kw = Dict(DEFAULTS)
for line in open(fname, 'rb'):
for line in open(fname, 'r'):
if not line.startswith('///'):
continue

Expand Down Expand Up @@ -97,7 +97,7 @@ def compile_file(fname, arch):
continue

# Write extra configuration to the config.yml file.
with open(os.path.join(arch, "config.yml"), "a+b") as f:
with open(os.path.join(arch, "config.yml"), "a+") as f:
if kw.FINISH == 'yes' or kw.PIPE == 'yes' or kw.FREE == 'yes':
f.write("%s:\n" % fname[:-2])
f.write(" options:\n")
Expand Down Expand Up @@ -137,7 +137,7 @@ def compile_file(fname, arch):
lines += compile_file(fname, 'x86')
lines += compile_file(fname, 'x64')

with open(os.path.join(curdir, 'Makefile'), 'wb') as f:
with open(os.path.join(curdir, 'Makefile'), 'w') as f:
f.write('MAKEFLAGS = -j8\n')
f.write('all: %s\n' % ' '.join(ALL))
f.write('clean:\n\trm -f %s\n\n' % ' '.join(ALL))
Expand Down
32 changes: 17 additions & 15 deletions utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import sys
import yaml
from yaml import Loader

class DefinitionProcessor(object):
def __init__(self, data_dir):
Expand All @@ -42,14 +43,15 @@ def read_document(self, sig):
doc = docutils.utils.new_document(os.path.basename(sig),
self.parser_settings())
parser = docutils.parsers.rst.Parser()
parser.parse(open(sig, 'rb').read(), doc)
with open(sig, 'r') as fin:
parser.parse(fin.read(), doc)
return parser

def template(self, name):
return self.templ_env.get_template('%s.jinja2' % name)

def render(self, template, path, **kwargs):
with open(path, 'wb') as f:
with open(path, 'w') as f:
f.write(self.template(template).render(**kwargs))


Expand Down Expand Up @@ -77,22 +79,22 @@ def __init__(self, data_dir, out_dir, sig_dirpath, flags, insns):
self.sig_dirpath = sig_dirpath

self.types = {}
for line in open(types_path, 'rb'):
for line in open(types_path, 'r'):
key, value = line.split('=', 1)
self.types[key.strip()] = value.strip()

self.is_success = {}
for line in open(is_success_path, 'rb'):
for line in open(is_success_path, 'r'):
key, value = line.split('=', 1)
self.is_success[key.strip()] = value.strip()

self.dereference = {}
for line in open(dereference_path, 'rb'):
for line in open(dereference_path, 'r'):
key, value = line.split('=', 1)
self.dereference[key.strip()] = value.strip()

self.base_sigs = []
for entry in json.load(open(base_sigs_path, 'rb')):
for entry in json.load(open(base_sigs_path, 'r')):
entry['is_hook'] = False
entry['signature']['special'] = False
for param in entry['parameters']:
Expand Down Expand Up @@ -295,15 +297,14 @@ def normalize(self, doc):
children = entry.children

if apiname.startswith('_'):
print>>sys.stderr, \
'Skipping ignored API Signature:', apiname[1:]
print('Skipping ignored API Signature:', apiname[1:], file=sys.stderr)
continue

row = copy.deepcopy(global_values)

row['apiname'] = apiname

for x in xrange(1, len(children), 2):
for x in range(1, len(children), 2):
try:
key, value = self._parse_paragraph(children[x],
children[x+1])
Expand Down Expand Up @@ -506,11 +507,11 @@ def list_categories(self):
category = sig['signature']['category']
if category not in categories:
categories[category] = None
print category
print(category)

def list_apis(self):
for sig in self.sigs:
print sig['signature']['category'], sig['apiname']
print(sig['signature']['category'], sig['apiname'])

class FlagsProcessor(object):
def __init__(self, data_dir, output_directory):
Expand Down Expand Up @@ -556,7 +557,7 @@ def normalize(self, doc):

row = dict(name=flagname, value=[], enum=[])

for x in xrange(1, len(children), 2):
for x in range(1, len(children), 2):
try:
key, value = self._parse_paragraph(children[x],
children[x+1])
Expand Down Expand Up @@ -627,7 +628,7 @@ def parse_logging(self, l):
if not l:
return []

if isinstance(l, basestring):
if isinstance(l, str):
l = [l]

r = []
Expand Down Expand Up @@ -666,7 +667,7 @@ def make_signature(self, arguments):
def process(self):
methods = []
for filepath in self.insnfiles:
doc = yaml.load(open(filepath, "rb"))
doc = yaml.load(open(filepath, "r"), Loader=Loader)
if not doc:
continue
glob = doc.pop("global", {})
Expand Down Expand Up @@ -728,7 +729,8 @@ def write(self, apis):
"methods": self.methods,
"modules": self.modules,
})
open(self.outfile, "wb").write(content)
with open(self.outfile, "w") as fout:
fout.write(content)

def render(self, docname, apis, variables, dirpath="data/"):
for method in self.methods:
Expand Down