-
Notifications
You must be signed in to change notification settings - Fork 31
/
check_file.py
30 lines (23 loc) · 1.12 KB
/
check_file.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import sys
class MissingFieldError(Exception):
def __init__(self, message):
self.message = message
class MetadataFieldError(Exception):
def __init__(self, message):
self.message = message
def check_file(path):
with open(path) as f:
contract_json = json.load(f)
if(contract_json.get('name') is None or contract_json.get('chainId') is None or contract_json.get('address') is None or contract_json.get('metadata') is None or contract_json.get('version') is None):
raise MissingFieldError('Require Field missing, name,chainId,address,metadata,version is required, please check the read me file')
if(contract_json.get('metadata').get('output') is None or contract_json.get('metadata').get('output').get('abi') is None):
raise MissingFieldError('Require Field missing, metadata.output.abi is required, please check the read me file')
if __name__ == "__main__":
file_path = sys.argv[1]
filetype = file_path.split('.')[-1]
if filetype == 'json':
print(file_path)
check_file(file_path)