Refactor updater for more type annotation
Change-Id: I3ab3463c6f1fd1cdc4df099e8dff21685cbc722b
diff --git a/base_updater.py b/base_updater.py
new file mode 100644
index 0000000..74b688d
--- /dev/null
+++ b/base_updater.py
@@ -0,0 +1,72 @@
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Base class for all updaters."""
+
+from pathlib import Path
+
+import fileutils
+import metadata_pb2 # type: ignore
+
+
+class Updater:
+ """Base Updater that defines methods common for all updaters."""
+ def __init__(self, proj_path: Path, old_url: metadata_pb2.URL,
+ old_ver: str) -> None:
+ self._proj_path = fileutils.get_absolute_project_path(proj_path)
+ self._old_url = old_url
+ self._old_ver = old_ver
+
+ self._new_url = metadata_pb2.URL()
+ self._new_url.CopyFrom(old_url)
+ self._new_ver = old_ver
+
+ def is_supported_url(self) -> bool:
+ """Returns whether the url is supported."""
+ raise NotImplementedError()
+
+ def check(self) -> None:
+ """Checks whether a new version is available."""
+ raise NotImplementedError()
+
+ def update(self) -> None:
+ """Updates the package.
+
+ Has to call check() before this function.
+ """
+ raise NotImplementedError()
+
+ @property
+ def project_path(self) -> Path:
+ """Gets absolute path to the project."""
+ return self._proj_path
+
+ @property
+ def current_version(self) -> str:
+ """Gets the current version."""
+ return self._old_ver
+
+ @property
+ def current_url(self) -> metadata_pb2.URL:
+ """Gets the current url."""
+ return self._old_url
+
+ @property
+ def latest_version(self) -> str:
+ """Gets latest version."""
+ return self._new_ver
+
+ @property
+ def latest_url(self) -> metadata_pb2.URL:
+ """Gets URL for latest version."""
+ return self._new_url