3 Commits
0.0.6 ... 0.0.7

Author SHA1 Message Date
639265f718 Merge pull request #3 from snegov/dependabot/pip/requests-2.31.0
Bump requests from 2.27.1 to 2.31.0
2023-09-14 16:24:59 -07:00
6af5eb1b26 Wait for seafile daemon to start 2023-09-14 16:22:02 -07:00
dependabot[bot]
43237dc1f3 Bump requests from 2.27.1 to 2.31.0
Bumps [requests](https://github.com/psf/requests) from 2.27.1 to 2.31.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.27.1...v2.31.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-23 03:15:40 +00:00
3 changed files with 36 additions and 4 deletions

View File

@@ -9,7 +9,7 @@ from cached_property import cached_property_with_ttl
import requests
from dsc import consts
from dsc.misc import create_dir
from dsc.misc import create_dir, hide_password
_lg = logging.getLogger(__name__)
@@ -29,6 +29,7 @@ class SeafileClient:
def token(self):
if self.__token is None:
url = f"{self.url}/api2/auth-token/"
_lg.info("Fetching token: %s", url)
r = requests.post(url, data={"username": self.user,
"password": self.password})
if r.status_code != 200:
@@ -39,6 +40,7 @@ class SeafileClient:
@cached_property_with_ttl(ttl=60)
def remote_libraries(self) -> dict:
url = f"{self.url}/api2/repos/"
_lg.info("Fetching remote libraries: %s", url)
auth_header = {"Authorization": f"Token {self.token}"}
r = requests.get(url, headers=auth_header)
if r.status_code != 200:
@@ -62,11 +64,12 @@ class SeafileClient:
'-d', lib_dir,
'-u', self.user,
'-p', self.password]
cmd = ' '.join(cmd)
subprocess.run(['su', '-', consts.DEFAULT_USERNAME, '-c', cmd])
_lg.info("Syncing library %s: %s", lib_name, ' '.join(hide_password(cmd, self.password)))
subprocess.run(['su', '-', consts.DEFAULT_USERNAME, '-c', ' '.join(cmd)])
def get_status(self):
cmd = 'seaf-cli status'
_lg.debug("Fetching seafile client status: %s", cmd)
out = subprocess.check_output(['su', '-', consts.DEFAULT_USERNAME, '-c', cmd])
out = out.decode().splitlines()
@@ -92,6 +95,7 @@ class SeafileClient:
def get_local_libraries(self) -> set:
cmd = 'seaf-cli list'
_lg.info("Listing local libraries: %s", cmd)
out = subprocess.check_output(['su', '-', consts.DEFAULT_USERNAME, '-c', cmd])
out = out.decode().splitlines()[1:] # first line is a header
@@ -102,6 +106,26 @@ class SeafileClient:
return local_libs
def check_seaf_daemon_is_ready() -> bool:
cmd = 'seaf-cli status'
_lg.info("Checking seafile daemon status: %s", cmd)
proc = subprocess.run(
['su', '-', consts.DEFAULT_USERNAME, '-c', cmd],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
return proc.returncode == 0
def start_seaf_daemon():
cmd = 'seaf-cli start'
_lg.info("Starting seafile daemon: %s", cmd)
subprocess.run(['su', '-', consts.DEFAULT_USERNAME, '-c', cmd])
_lg.info("Waiting for seafile daemon to start")
while True:
if check_seaf_daemon_is_ready():
break
time.sleep(5)
_lg.info("Seafile daemon is ready")

View File

@@ -19,3 +19,11 @@ def create_dir(dir_path: str):
else:
if not os.path.isdir(dir_path):
raise RuntimeError(f"Data dir {dir_path} is not a directory")
def hide_password(cmd: list, password: str) -> list:
cmd = cmd.copy()
for i, arg in enumerate(cmd):
if arg == password:
cmd[i] = '********'
return cmd

View File

@@ -1,2 +1,2 @@
cached_property==1.5.2
requests==2.27.1
requests==2.31.0