servod: move scratch into utils/scratch.py
This change moves the scratch util into its own utility location.
It breaks apart servodutil into Instance, the new 'tool' and scratch,
the utility backing the tool. For now, the API remains the same.
BUG=chromium:1052541
TEST=python2 -m pytest servo_parsing_unittest.py
> 18 passed in 0.05 seconds
TEST= python2 -m pytest servodutil_test.py
> 2 passed in 0.01 seconds
TEST=python2 -m pytest utils/scratch_test.py
> 17 passed in 0.07 seconds
TEST=sudo servod -b atlas &
sudo servodutil rebuild -p 9999
> port 9999 already known.
sudo servodutil rebuild -p 9998
> Could not rebuild entry for port 9998
sudo servodutil show -p 9999
> port : 9999
> serials : [u'C1804020019', u'SNCQ00098']
> pid : 200170
sudo servodutil show-all
> port : 9999
> serials : [u'C1804020019', u'SNCQ00098']
> pid : 200170
sudo servodutil show -p 9998
> No servod scratch entry found under id: 9998.
sudo servodutil stop -p 9999
> SIGTERM sent to servod instance associated with id 9999.
> Servod instance associated with id 9999 turned down.
sudo servodutil stop -p 9998
> No servod scratch entry found under id: 9998.
TEST=sudo servodutil show-all
> No entries found.
Change-Id: Ia9a83d8f651cff1e85c7e7bc491647635e066fd7
Signed-off-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/hdctools/+/2058192
Reviewed-by: Brian Nemec <bnemec@chromium.org>
diff --git a/servo/servo_parsing.py b/servo/servo_parsing.py
index 8e853e2..a7602c4 100644
--- a/servo/servo_parsing.py
+++ b/servo/servo_parsing.py
@@ -10,7 +10,7 @@
import client
import servo_logging
-import servodutil
+import utils.scratch
# A brief overview of the classes found here, and their abilities.
@@ -442,10 +442,10 @@
# Passing None here uses the default production logic while passing any
# other directory can be used for testing. No need to check whether
# |self._scratchdir| is None.
- scratch = servodutil.ServoScratch(self._scratchdir)
+ scratch = utils.scratch.Scratch(self._scratchdir)
try:
entry = scratch.FindById(opts.serialname)
- except servodutil.ServodUtilError:
+ except utils.scratch.ScratchError:
self.error('No servod instance running for device with serialname: %r' %
opts.serialname)
opts.port = int(entry['port'])