no need to recheck that every time in local testing

This commit is contained in:
simon 2021-09-13 11:08:28 +07:00
parent 3c003750a8
commit 9a12db4077

View File

@ -2,6 +2,7 @@
""" check requirements.txt for outdated packages """ """ check requirements.txt for outdated packages """
import sys import sys
import pathlib
import requests import requests
@ -10,8 +11,20 @@ class Requirements:
""" handle requirements.txt """ """ handle requirements.txt """
FILE_PATH = 'tubearchivist/requirements.txt' FILE_PATH = 'tubearchivist/requirements.txt'
LOCK = '/tmp/tubearchivist-requirements.lock'
def __init__(self): def __init__(self):
self.exists = self.checked_today()
self.all_requirements = False
self.all_updates = False
def checked_today(self):
""" skip requirements check when lock file exists """
exists = pathlib.Path(self.LOCK).exists()
return exists
def look_for_updates(self):
""" look through requirements and check for updates """
self.all_requirements = self.get_dependencies() self.all_requirements = self.get_dependencies()
self.all_updates = self.check_packages() self.all_updates = self.check_packages()
@ -59,6 +72,9 @@ class Requirements:
if not all_updates: if not all_updates:
print('no updates found') print('no updates found')
# remember that
pathlib.Path(self.LOCK).touch()
return all_updates return all_updates
def apply_updates(self): def apply_updates(self):
@ -82,8 +98,13 @@ class Requirements:
print('requirements.txt updates') print('requirements.txt updates')
if __name__ == "__main__": def main():
""" main to check for updates """
handler = Requirements() handler = Requirements()
if handler.exists:
return
handler.look_for_updates()
if handler.all_updates: if handler.all_updates:
input_response = input('\nupdate requirements.txt? [y/n] ') input_response = input('\nupdate requirements.txt? [y/n] ')
if input_response == 'y': if input_response == 'y':
@ -91,3 +112,6 @@ if __name__ == "__main__":
else: else:
print('cancle update...') print('cancle update...')
sys.exit(1) sys.exit(1)
if __name__ == "__main__":
main()