Clean up os path coding
Clean up os path coding, use os.path.join and use __file__ to determine
current script directory.
from __future__ import absolute_import
-import inspect
import json
import os
import six
@@ -38,14 +37,14 @@ content_models = {
}
def main():
- scripts_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
- schemas_dir = scripts_dir + '/../../contrib/schemas'
+ scripts_dir = os.path.dirname(os.path.abspath(__file__))
+ schemas_dir = os.path.abspath(os.path.join(scripts_dir, '../../contrib/schemas'))
for name, model in six.iteritems(content_models):
schema_text = json.dumps(model.schema, indent=4)
print('Generated schema for the "%s" model.' % name)
- schema_file = os.path.abspath(schemas_dir + '/' + name + '.json')
+ schema_file = os.path.join(schemas_dir, name + '.json')
print('Schema will be written to "%s".' % schema_file)
with open(schema_file, 'w') as f:
