obspyDMT icon indicating copy to clipboard operation
obspyDMT copied to clipboard

locate, only_one

Open mary-tsekhmistrenko opened this issue 8 years ago • 1 comments

+def locate(root='.', target='info', only_one=False):
     """
     locates a subdirectory within a directory
     :param root:
@@ -382,9 +382,15 @@ def locate(root='.', target='info'):
     :return:
     """
     matches = []
+    found_one = False
     for root, dirnames, filenames in os.walk(root):
         for dirname in fnmatch.filter(dirnames, target):
             matches.append(os.path.join(root, dirname))
+            found_one = True
+            if only_one:
+                break
+        if found_one and only_one:
+            break

     return matches

mary-tsekhmistrenko avatar Dec 10 '16 12:12 mary-tsekhmistrenko

diff --git a/obspyDMT/utils/data_handler.py b/obspyDMT/utils/data_handler.py
index ff06d07..8ae4fc6 100644
--- a/obspyDMT/utils/data_handler.py
+++ b/obspyDMT/utils/data_handler.py
@@ -438,9 +438,11 @@ def arc_serial_parallel(stas_avail, event, input_dics, target_path,
     """
     print '%s -- event: %s' % (req_cli, target_path)
 
-    client_arclink = Client_arclink(user='[email protected]',
-                                    timeout=input_dics['arc_wave_timeout'])
-
+    client_arclink = Client_arclink(user='XXX', 
+                                    timeout=input_dics['arc_wave_timeout'], 
+                                    dcid_keys='XXX]', 
+                                    dcid_key_file='dcidpasswords.txt' )
+	
     if input_dics['req_parallel']:
         par_jobs = []
         st_counter = 0
diff --git a/obspyDMT/utils/event_handler.py b/obspyDMT/utils/event_handler.py
index 914c4c2..2438579 100644
--- a/obspyDMT/utils/event_handler.py
+++ b/obspyDMT/utils/event_handler.py
@@ -126,7 +126,7 @@ def read_info(input_dics):
     :param input_dics:
     :return:
     """
-    evs_info = locate(input_dics['datapath'], 'EVENTS-INFO')
+    evs_info = locate(input_dics['datapath'], 'EVENTS-INFO', only_one=True)
     if len(evs_info) == 0:
         return "no_local"
     if len(evs_info) > 1:
diff --git a/obspyDMT/utils/local_handler.py b/obspyDMT/utils/local_handler.py
index 8086fb3..1190113 100644
--- a/obspyDMT/utils/local_handler.py
+++ b/obspyDMT/utils/local_handler.py
@@ -49,7 +49,7 @@ def process_data(input_dics, event):
     :param event:
     :return:
     """
-    target_path = locate(input_dics['datapath'], event['event_id'])
+    target_path = locate(input_dics['datapath'], event['event_id'], search_depth=1)
 
     if len(target_path) == 0:
         return
diff --git a/obspyDMT/utils/utility_codes.py b/obspyDMT/utils/utility_codes.py
index dd7b579..9a5c9fb 100644
--- a/obspyDMT/utils/utility_codes.py
+++ b/obspyDMT/utils/utility_codes.py
@@ -374,7 +374,7 @@ def create_station_event(address):
 # ##################### locate ##########################################
 
 
-def locate(root='.', target='info'):
+def locate(root='.', target='info', search_depth=10, only_one=True):
     """
     locates a subdirectory within a directory
     :param root:
@@ -382,9 +382,19 @@ def locate(root='.', target='info'):
     :return:
     """
     matches = []
+    found_one = False
+    cur_depth = 0
     for root, dirnames, filenames in os.walk(root):
         for dirname in fnmatch.filter(dirnames, target):
             matches.append(os.path.join(root, dirname))
+            found_one = True
+            if only_one:
+                break
+        if found_one and only_one:
+            break
+        if cur_depth > search_depth:
+            break
+        cur_depth += 1
 
     return matches

kasra-hosseini avatar Jan 26 '17 17:01 kasra-hosseini