-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiver_mock.py
44 lines (35 loc) · 1.12 KB
/
archiver_mock.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
import time
from random import random
from threading import Thread
class Archiver:
archive_status = "Waiting"
archive_progress = 0
thread = None
def status(self):
return Archiver.archive_status
def progress(self):
return Archiver.archive_progress
def run(self):
if Archiver.archive_status == "Waiting":
Archiver.archive_status = "Running"
Archiver.archive_progress = 0
Archiver.thread = Thread(target=self.run_impl)
Archiver.thread.start()
def run_impl(self):
for i in range(10):
time.sleep(1 * random())
if Archiver.archive_status != "Running":
return
Archiver.archive_progress = (i + 1) / 10
print("Here... " + str(Archiver.archive_progress))
time.sleep(1)
if Archiver.archive_status != "Running":
return
Archiver.archive_status = "Complete"
def archive_file(self):
return 'vocabs.json'
def reset(self):
Archiver.archive_status = "Waiting"
@classmethod
def get(cls):
return Archiver()