-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disk.py
50 lines (40 loc) · 1.74 KB
/
Disk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import webdav.client as wc
import LogSystem
# request.setopt(pycurl.CAINFO, certifi.where())
class Disk:
def __init__(self, hostname, login, password):
self.client = None
self.options = dict()
self.options['webdav_hostname'] = hostname
self.options['webdav_login'] = login
self.options['webdav_password'] = password
def initial_client(self):
self.client = wc.Client(self.options)
def get_free_space(self):
if self.client is None or not self.client.check():
self.initial_client()
return self.client.free()
def exist_file(self, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
return self.client.check(remote_path)
def delete_file(self, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
return self.client.clean(remote_path)
def upload_file(self, local_path, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
self.client.upload_sync(remote_path=remote_path, local_path=local_path)
def download_file(self, local_path, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
self.client.download_sync(remote_path=remote_path, local_path=local_path)
def publish_file(self, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
return self.client.publish(remote_path)
def unpublish_file(self, remote_path):
if self.client is None or not self.client.check():
self.initial_client()
return self.client.publish(remote_path)