benten files
目的
- ファイル検索を行います。
Warning
事前にログイン認証を行う必要があります。
概要
- 認証時のアカウントでアクセスが許可されたデータのみ情報を取得できます。
- ディレクトリ、またはファイルを指定して検索ができます。
- クエリで検索ができます。
利用例
- Help
s benten.py files -h usage: benten files [-h] [--register_name [REGISTER_NAME]] [--file [FILE]] [--query [QUERY]] [--flag_recursive] [--flag_register_name] [--flag_uuid_register_directory] [--size [SIZE]] [--begin_from [BEGIN_FROM]] [--flag_own] optional arguments: -h, --help show this help message and exit --register_name [REGISTER_NAME], -r [REGISTER_NAME] register_name --file [FILE], -f [FILE] directory or file --query [QUERY], -q [QUERY] query --flag_recursive, -s output file_list with recursive search for directory --flag_register_name, -n output register_name list --flag_uuid_register_directory, -u output file_list with uuid_register_directory --size [SIZE] search size --begin_from [BEGIN_FROM] id to begin search --flag_own, -o output with own file_list
- ディレクトリ指定での検索
$ benten files -f "/SPring-8/BL14B2/data2/temp" ### benten files ### [Repository::authorize] access_token = 0b513fb250d9456a8f900533bd91aeda ==> response { "total_count":1, "size":0, "begin_from":0, "file_list":[ { "size":109, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.json", "time":"2019-03-12 11:33:02", "hash":"5feb764597a9de85748a874897e567b7", "uuid_name":"d82d86d1-9c91-4cd0-b9a4-16f489803d9b", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":458, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.system.json", "time":"2019-03-09 21:17:47", "hash":"f5c1e6361041f0a776bc7fcc1d5559ad", "uuid_name":"d969744f-bb40-4c58-8056-3663b2484abd", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" } ] }
- クエリ指定での検索 (1)
$ benten.py files -q Cu ### benten files ### [Repository::authorize] access_token = 0b513fb250d9456a8f900533bd91aeda ==> response { "total_count":1, "size":0, "begin_from":0, "file_list":[ { "size":109, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.json", "time":"2019-03-12 11:33:02", "hash":"5feb764597a9de85748a874897e567b7", "uuid_name":"d82d86d1-9c91-4cd0-b9a4-16f489803d9b", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":458, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.system.json", "time":"2019-03-09 21:17:47", "hash":"f5c1e6361041f0a776bc7fcc1d5559ad", "uuid_name":"d969744f-bb40-4c58-8056-3663b2484abd", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":250629, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.dat", "time":"2013-01-26 08:54:37", "hash":"6603fa8c31eea4f41bb54048a152c06b", "uuid_name":"7d323d63-ad5e-42e0-a295-4fa47c372b63", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":15357, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.ex3", "time":"2013-01-26 08:54:36", "hash":"da87605ca96185f99bd577ee5fa5d8f7", "uuid_name":"8554d6f1-c76c-4a7a-b13b-9cfe979a3f2c", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":14977, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.txt", "time":"2013-01-26 08:54:36", "hash":"595f72c1168ba7271adf2855b79db00e", "uuid_name":"3baf1306-1106-41db-b8cb-1823f7d8e47f", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":535, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/README.csv", "time":"2015-11-27 08:30:36", "hash":"04fc584126773205d6b9d18e49cd90f0", "uuid_name":"726de17b-c35c-477b-8318-8718616a124c", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" } ] }
- クエリ指定での検索 (2)
$ benten.py files -q "Cu and @subject@proposal_number:2014S0000" ### benten files ### [Repository::authorize] access_token = 0b513fb250d9456a8f900533bd91aeda ==> response { "total_count":1, "size":0, "begin_from":0, "file_list":[ { "size":109, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.json", "time":"2019-03-12 11:33:02", "hash":"5feb764597a9de85748a874897e567b7", "uuid_name":"d82d86d1-9c91-4cd0-b9a4-16f489803d9b", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":458, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613.system.json", "time":"2019-03-09 21:17:47", "hash":"f5c1e6361041f0a776bc7fcc1d5559ad", "uuid_name":"d969744f-bb40-4c58-8056-3663b2484abd", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":250629, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.dat", "time":"2013-01-26 08:54:37", "hash":"6603fa8c31eea4f41bb54048a152c06b", "uuid_name":"7d323d63-ad5e-42e0-a295-4fa47c372b63", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":15357, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.ex3", "time":"2013-01-26 08:54:36", "hash":"da87605ca96185f99bd577ee5fa5d8f7", "uuid_name":"8554d6f1-c76c-4a7a-b13b-9cfe979a3f2c", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":14977, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/Cu-K_Cu-foil_Si111_50ms_120613.txt", "time":"2013-01-26 08:54:36", "hash":"595f72c1168ba7271adf2855b79db00e", "uuid_name":"3baf1306-1106-41db-b8cb-1823f7d8e47f", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" }, { "size":535, "name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613/README.csv", "time":"2015-11-27 08:30:36", "hash":"04fc584126773205d6b9d18e49cd90f0", "uuid_name":"726de17b-c35c-477b-8318-8718616a124c", "register_name":"/SPring-8/BL14B2/data2/temp/Cu-K_Cu-foil_Si111_50ms_120613" } ] }
Pythonモジュールとの対応
- benten_client.rest_data.Files を利用
- 利用例 (example/benten_files.pyから)
#!/usr/bin/env python ''' example: files usage: python benten_files.py ... ''' import benten_client import argparse from logging import getLogger, StreamHandler, DEBUG logger = getLogger(__name__) handler = StreamHandler() handler.setLevel(DEBUG) logger.setLevel(DEBUG) logger.addHandler(handler) logger.propagate = False # ... parameters parser = argparse.ArgumentParser(description="example: files") parser.add_argument("--register_name", "-r", nargs="?", action="append", help="register_name") parser.add_argument("--file", "-f", nargs="?", action="append", help="directory or file") parser.add_argument("--query", "-q", nargs="?", help="query") parser.add_argument("--flag_recursive", "-s", action="store_const", const=1, help="output file_list with recursive search for directory") parser.add_argument("--flag_register_name", "-n", action="store_const", const=1, help="output with register_name list") parser.add_argument("--flag_uuid_register_directory", "-u", action="store_const", const=1, help="output file list with uuid_register_directory") parser.add_argument("--size", nargs="?", help="search size") parser.add_argument("--begin_from", nargs="?", help="id to begin search") parser.add_argument("--flag_own", "-o", action="store_const", const=1, help="output with own file_list") args = parser.parse_args() register_name_list = args.register_name file_list = args.file query = args.query flag_recursive = args.flag_recursive flag_register_name = args.flag_register_name flag_uuid_register_directory = args.flag_uuid_register_directory size = args.size begin_from = args.begin_from flag_own = args.flag_own v = {} if register_name_list is not None: v["register_name_list"] = register_name_list if file_list is not None: v["file_list"] = file_list if query is not None: v["query"] = query if flag_recursive is not None: v["flag_recursive"] = flag_recursive if flag_register_name is not None: v["flag_register_name"] = flag_register_name if flag_uuid_register_directory is not None: v["flag_uuid_register_directory"] = flag_uuid_register_directory if size is not None: v["size"] = size if begin_from is not None: v["begin_from"] = begin_from if flag_own is not None: v["flag_own"] = flag_own repo = benten_client.Repository() logger.debug("# set access token") repo.authorize(benten_client.access_token()) logger.debug("# benten files") ret_dict = repo.data.files.post(**v) benten_client.log("==> response") benten_client.out_json(ret_dict)