Skip to content

Commit 233fae3

Browse files
authored
Merge pull request #10 from zSeriesGuy/beta
v1.2.2
2 parents 651bacf + 8ff96b8 commit 233fae3

File tree

9 files changed

+87
-7
lines changed

9 files changed

+87
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.2.2 (2019-10-19)
4+
* Add settings and process for deleting logs, transcripts, and recordings after a specified number of days.
5+
36
## v1.2.1 (2019-10-19)
47
* Microsoft Azure Speech-to-Text Cloud service is not available on some platforms. Added support for detecting failure to load service.
58

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ SpeakReader requires Python 3.6 or higher.
2525

2626

2727
## Installation
28-
Installation instructions can be found in the wiki.
28+
[Installation instructions](https://github.com/zSeriesGuy/SpeakReader/wiki) can be found in the wiki.
2929

3030

3131
## Usage

html/manage.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,28 @@ <h4>General</h4>
331331
<label for="log_dir" class="font-weight-bold">Logs Folder</label>
332332
<input id="log_dir" type="text" class="form-control" name="log_dir" value="${config['log_dir']}" size="30">
333333
<small class="form-text">Optional: Change the folder where you would like SpeakReader to store the SpeakReader console logs.<br><strong>Restart Required.</strong> A change here will become active with the next restart.</small>
334+
335+
<div class="row mt-3">
336+
<label for="log_retention_days" class="font-weight-bold col-md-2 col-form-label">Retention Days</label>
337+
<div class="col-md-2">
338+
<input id="log_retention_days" type="number" class="form-control" name="log_retention_days" value="${config['log_retention_days']}" min="1">
339+
</div>
340+
</div>
341+
<small class="form-text">Number of days to keep log files before automatically deleting them. Set to blank to not automatically delete them.</small>
334342
</div>
335343

336344
<div class="form-group">
337345
<label for="transcripts_folder" class="font-weight-bold">Transcripts Folder</label>
338346
<input id="transcripts_folder" type="text" class="form-control" name="transcripts_folder" value="${config['transcripts_folder']}" size="30">
339347
<small class="form-text">Optional: Change the folder where you would like SpeakReader to store the transcripts.<br><strong>Restart Required.</strong> A change here will become active with the next restart.</small>
348+
349+
<div class="row mt-3">
350+
<label for="transcript_retention_days" class="font-weight-bold col-md-2 col-form-label">Retention Days</label>
351+
<div class="col-md-2">
352+
<input id="transcript_retention_days" type="number" class="form-control" name="transcript_retention_days" value="${config['transcript_retention_days']}" min="1">
353+
</div>
354+
</div>
355+
<small class="form-text">Number of days to keep transcript files before automatically deleting them. Set to blank to not automatically delete them.</small>
340356
</div>
341357

342358

@@ -351,6 +367,14 @@ <h4>General</h4>
351367
<label for="recordings_folder" class="font-weight-bold">Recordings Folder</label>
352368
<input id="recordings_folder" type="text" class="form-control" name="recordings_folder" value="${config['recordings_folder']}" size="30">
353369
<small class="form-text">Optional: Change the folder where you would like SpeakReader to store the audio recordings.<br><strong>Restart Required.</strong> A change here will become active with the next restart.</small>
370+
371+
<div class="row mt-3">
372+
<label for="recording_retention_days" class="font-weight-bold col-md-2 col-form-label">Retention Days</label>
373+
<div class="col-md-2">
374+
<input id="recording_retention_days" type="number" class="form-control" name="recording_retention_days" value="${config['recording_retention_days']}" min="1">
375+
</div>
376+
</div>
377+
<small class="form-text">Number of days to keep recording files before automatically deleting them. Set to blank to not automatically delete them.</small>
354378
</div>
355379
</div>
356380
</div>
@@ -808,6 +832,9 @@ <h4 class="modal-title">Confirm</h4>
808832
$('#git_token').val(config.git_token);
809833
$('#git_remote').val(config.git_remote);
810834
$('#git_path').val(config.git_path);
835+
$('#log_retention_days').val(config.log_retention_days);
836+
$('#transcript_retention_days').val(config.transcript_retention_days);
837+
$('#recording_retention_days').val(config.recording_retention_days);
811838

812839
$('#git_branch').val(config.git_branch);
813840

requirements.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tzlocal
1919
passlib
2020
wheel
2121
samplerate
22+
apscheduler

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#
55
# pip-compile
66
#
7+
apscheduler==3.6.1
78
azure-cognitiveservices-speech==1.7.0 ; sys_platform in "win32 macos" or (sys_platform == "linux" and platform_machine in "AMD64")
89
cachetools==3.1.1 # via google-auth
910
certifi==2019.9.11 # via requests
@@ -39,12 +40,12 @@ pyaudio==0.2.11
3940
pycparser==2.19 # via cffi
4041
pyjwt==1.7.1
4142
python-dateutil==2.8.0
42-
pytz==2019.3 # via google-api-core, tempora, tzlocal
43+
pytz==2019.3 # via apscheduler, google-api-core, tempora, tzlocal
4344
pywin32==225 ; sys_platform == "win32"
4445
requests==2.22.0 # via google-api-core, ibm-cloud-sdk-core, ibm-watson
4546
rsa==4.0 # via google-auth
4647
samplerate==0.1.0
47-
six==1.12.0 # via cheroot, configobj, google-api-core, google-api-python-client, google-auth, grpcio, pip-tools, protobuf, python-dateutil, tempora, websocket-client
48+
six==1.12.0 # via apscheduler, cheroot, configobj, google-api-core, google-api-python-client, google-auth, grpcio, pip-tools, protobuf, python-dateutil, tempora, websocket-client
4849
tempora==1.14.1 # via portend
4950
tzlocal==2.0.0
5051
uritemplate==3.0.0 # via google-api-python-client
@@ -54,4 +55,4 @@ wheel==0.33.6
5455
zc.lockfile==2.0 # via cherrypy
5556

5657
# The following packages are considered to be unsafe in a requirements file:
57-
# setuptools==41.4.0 # via google-api-core, protobuf, zc.lockfile
58+
# setuptools==41.4.0 # via apscheduler, google-api-core, protobuf, zc.lockfile

speakreader/__init__.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import pyaudio
2323
import cherrypy
2424
import json
25+
import datetime
26+
from apscheduler.schedulers.background import BackgroundScheduler
27+
from apscheduler.triggers.interval import IntervalTrigger
28+
2529

2630
try:
2731
import webbrowser
@@ -140,6 +144,14 @@ def __init__(self, initOptions):
140144
if CONFIG.LAUNCH_BROWSER and not initOptions['nolaunch']:
141145
launch_browser(CONFIG.HTTP_HOST, self.HTTP_PORT, CONFIG.HTTP_ROOT + 'manage')
142146

147+
###################################################################################################
148+
# Run cleanup of old logs, transcripts, and recordings and start a scheduler to run every 24 hours
149+
###################################################################################################
150+
self.cleanup_files()
151+
self.scheduler = BackgroundScheduler()
152+
self.scheduler.add_job(self.cleanup_files, 'interval', hours=24)
153+
self.scheduler.start()
154+
143155
SpeakReader._INITIALIZED = True
144156

145157
@property
@@ -213,6 +225,7 @@ def stopTranscribeEngine(self):
213225
def shutdown(self, restart=False, update=False, checkout=False):
214226
SpeakReader._INITIALIZED = False
215227
self.transcribeEngine.shutdown()
228+
self.scheduler.shutdown()
216229
CONFIG.write()
217230

218231
if not restart and not update and not checkout:
@@ -279,6 +292,35 @@ def get_input_device_list(self):
279292
return deviceList
280293

281294

295+
###################################################################################################
296+
# Delete any files over the retention days
297+
###################################################################################################
298+
def cleanup_files(self):
299+
logger.info("Running File Cleanup")
300+
def delete(path, days):
301+
try:
302+
days = int(days)
303+
except ValueError:
304+
return
305+
delete_date = datetime.datetime.now() - datetime.timedelta(days=days)
306+
with os.scandir(path=path) as files:
307+
for file in files:
308+
file_info = file.stat()
309+
if datetime.datetime.fromtimestamp(file_info.st_ctime) < delete_date:
310+
filename = os.path.join(path, file.name)
311+
logger.debug("Deleting: %s" % filename)
312+
os.remove(filename)
313+
314+
if CONFIG.LOG_RETENTION_DAYS != "":
315+
delete(CONFIG.LOG_DIR, CONFIG.LOG_RETENTION_DAYS)
316+
317+
if CONFIG.TRANSCRIPT_RETENTION_DAYS != "":
318+
delete(CONFIG.TRANSCRIPTS_FOLDER, CONFIG.TRANSCRIPT_RETENTION_DAYS)
319+
320+
if CONFIG.RECORDING_RETENTION_DAYS != "":
321+
delete(CONFIG.RECORDINGS_FOLDER, CONFIG.RECORDING_RETENTION_DAYS)
322+
323+
282324
def generate_uuid():
283325
return uuid.uuid4().hex
284326

speakreader/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,16 @@ def bool_int(value):
3939
'START_TRANSCRIBE_ON_STARTUP': (int, 'General', 1),
4040
'SHOW_INTERIM_RESULTS': (int, 'General', 1),
4141
'TRANSCRIPTS_FOLDER': (str, 'General', ''),
42+
'TRANSCRIPT_RETENTION_DAYS': (str, 'General', '30'),
4243
'ENABLE_CENSORSHIP': (int, 'General', 1),
4344
'CENSORED_WORDS': (list, 'General', ''),
4445
'LOG_DIR': (str, 'General', ''),
46+
'LOG_RETENTION_DAYS': (str, 'General', '30'),
4547
'ANON_REDIRECT': (str, 'General', 'http://www.nullrefer.com/?'),
4648
'SERVER_ENVIRONMENT': (str, 'Advanced', 'production'),
4749
'SAVE_RECORDINGS': (int, 'General', 1),
4850
'RECORDINGS_FOLDER': (str, 'General', ''),
51+
'RECORDING_RETENTION_DAYS': (str, 'General', '30'),
4952
'SPEECH_TO_TEXT_SERVICE': (str, 'General', 'google'),
5053
'GOOGLE_CREDENTIALS_FILE': (str, 'General', ''),
5154
'IBM_CREDENTIALS_FILE': (str, 'General', ''),

speakreader/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
PRODUCT = 'SpeakReader'
2-
VERSION_RELEASE = 'v1.2.1'
2+
VERSION_RELEASE = 'v1.2.2'
33
GITHUB_BRANCH = 'master'

speakreader/webserve.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,13 @@ def getSettings(self, **kwargs):
107107
config = {
108108
"start_transcribe_on_startup": speakreader.CONFIG.START_TRANSCRIBE_ON_STARTUP,
109109
"launch_browser": speakreader.CONFIG.LAUNCH_BROWSER,
110-
"transcripts_folder": speakreader.CONFIG.TRANSCRIPTS_FOLDER,
111110
"log_dir": speakreader.CONFIG.LOG_DIR,
112-
"save_recordings": speakreader.CONFIG.SAVE_RECORDINGS,
111+
"transcripts_folder": speakreader.CONFIG.TRANSCRIPTS_FOLDER,
113112
"recordings_folder": speakreader.CONFIG.RECORDINGS_FOLDER,
113+
"log_retention_days": speakreader.CONFIG.LOG_RETENTION_DAYS,
114+
"transcript_retention_days": speakreader.CONFIG.TRANSCRIPT_RETENTION_DAYS,
115+
"recording_retention_days": speakreader.CONFIG.TRANSCRIPT_RETENTION_DAYS,
116+
"save_recordings": speakreader.CONFIG.SAVE_RECORDINGS,
114117
"http_port": speakreader.CONFIG.HTTP_PORT,
115118
"enable_https": speakreader.CONFIG.ENABLE_HTTPS,
116119
"https_cert": speakreader.CONFIG.HTTPS_CERT,

0 commit comments

Comments
 (0)