Support new resource download scheme in test_tool and fetch_from_sandbox.py
@@ -22,6 +22,7 @@ def parse_args():
fetch_from.add_common_arguments(parser)
parser.add_argument('--resource-id', type=int, required=True)
parser.add_argument('--custom-fetcher')
+ parser.add_argument('--resource-file')
return parser.parse_args()
@@ -209,12 +210,44 @@ def fetch(resource_id, custom_fetcher):
return fetched_file, resource_info['file_name']
+def _get_resource_info_from_file(resource_file):
+ if resource_file is None or not os.path.exists(resource_file):
+ return None
+
+ RESOURCE_INFO_JSON = "resource_info.json"
+ RESOURCE_CONTENT_FILE_NAME = "resource"
+
+ resource_dir, resource_file = os.path.split(resource_file)
+ if resource_file != RESOURCE_CONTENT_FILE_NAME:
+ return None
+
+ resource_json = os.path.join(resource_dir, RESOURCE_INFO_JSON)
+ if not os.path.isfile(resource_json):
+ return None
+
+ try:
+ with open(resource_json, 'r') as j:
+ resource_info = json.load(j)
+ resource_info['file_name'] # check consistency
+ return resource_info
+ except:
+ logging.debug('Invalid %s in %s', RESOURCE_INFO_JSON, resource_dir)
+
+ return None
+
+
def main(args):
custom_fetcher = os.environ.get('YA_CUSTOM_FETCHER')
+ resource_info = _get_resource_info_from_file(args.resource_file)
+ if resource_info:
+ fetched_file = args.resource_file
+ file_name = resource_info['file_name']
+ else:
+ # This code should be merged to ya and removed.
fetched_file, file_name = fetch(args.resource_id, custom_fetcher)
- fetch_from.process(fetched_file, file_name, args, remove=not custom_fetcher)
+ fetch_from.process(fetched_file, file_name, args, remove=not custom_fetcher and not resource_info)
if __name__ == '__main__':
