[autotest] Integrate crashlog collection into repair workflow.

When a DUT goes offline before logs are gathered, we lose those
logs if the DUT is re-imaged.
To grab such logs as much as we can, we integrate crashlog
collection into the repair workflow.

BUG=chromium:215160
TEST=./server/autoserv -R -m <DUT ip> -r ~/tmp/repair
CQ-DEPEND=CL:221510

Change-Id: Ifd562bfd539b133381572aeec503d9a3940ab448
Reviewed-on: https://chromium-review.googlesource.com/219999
Reviewed-by: Fang Deng <fdeng@chromium.org>
Commit-Queue: Mungyung Ryu <mkryu@google.com>
Tested-by: Mungyung Ryu <mkryu@google.com>
diff --git a/server/site_utils.py b/server/site_utils.py
index b0fa276..7d95215 100644
--- a/server/site_utils.py
+++ b/server/site_utils.py
@@ -6,6 +6,7 @@
 import httplib
 import json
 import logging
+import os
 import random
 import re
 import time
@@ -309,3 +310,44 @@
         test_views[view['test_name']] = view['status']
 
     return test_views
+
+
+def parse_simple_config(config_file):
+    """Get paths by parsing a simple config file.
+
+    Each line of the config file is a path for a file or directory.
+    Ignore an empty line and a line starting with a hash character ('#').
+    One example of this kind of simple config file is
+    client/common_lib/logs_to_collect.
+
+    @param config_file: Config file path
+    @return: A list of directory strings
+    """
+    dirs = []
+    for l in open(config_file):
+        l = l.strip()
+        if l and not l.startswith('#'):
+            dirs.append(l)
+    return dirs
+
+
+def concat_path_except_last(base, sub):
+    """Concatenate two paths but exclude last entry.
+
+    Take two paths as parameters and return a path string in which
+    the second path becomes under the first path.
+    In addition, remove the last path entry from the concatenated path.
+    This works even when two paths are absolute paths.
+
+    e.g., /usr/local/autotest/results/ + /var/log/ =
+    /usr/local/autotest/results/var
+
+    e.g., /usr/local/autotest/results/ + /var/log/syslog =
+    /usr/local/autotest/results/var/log
+
+    @param base: Beginning path
+    @param sub: The path that is concatenated to base
+    @return: Concatenated path string
+    """
+    dirname = os.path.dirname(sub.rstrip('/'))
+    return os.path.join(base, dirname.strip('/'))