-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from efabless/migrate_to_poetry
Migrate to Poetry
- Loading branch information
Showing
12 changed files
with
715 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,47 @@ | ||
import os | ||
import json | ||
from venv import logger | ||
import requests | ||
import pkg_resources | ||
import subprocess | ||
from datetime import datetime, timedelta | ||
|
||
__dir__ = os.path.abspath(os.path.dirname(__file__)) | ||
version = subprocess.check_output( | ||
[ | ||
"python3", | ||
os.path.join( | ||
__dir__, | ||
"__version__.py", | ||
), | ||
], | ||
encoding="utf8", | ||
) | ||
from .__version__ import __version__ | ||
|
||
def check_for_updates(logger): | ||
package_name = 'ipmgr' | ||
current_version = subprocess.check_output( | ||
[ | ||
"python3", | ||
os.path.join( | ||
__dir__, | ||
"__version__.py", | ||
), | ||
], | ||
encoding="utf8", | ||
) | ||
|
||
config_file = os.path.join(os.path.expanduser('~'), '.ipm', 'ipm_package.json') | ||
def check_for_updates(logger): | ||
package_name = "ipmgr" | ||
config_file = os.path.join(os.path.expanduser("~"), ".ipm", "ipm_package.json") | ||
|
||
def load_last_check(): | ||
if os.path.exists(config_file): | ||
with open(config_file, 'r') as f: | ||
with open(config_file, "r") as f: | ||
return json.load(f) | ||
return {} | ||
|
||
def save_last_check(data): | ||
if not os.path.exists(os.path.join(os.path.expanduser('~'), '.ipm')): | ||
os.mkdir(os.path.join(os.path.expanduser('~'), '.ipm')) | ||
with open(config_file, 'w') as f: | ||
if not os.path.exists(os.path.join(os.path.expanduser("~"), ".ipm")): | ||
os.mkdir(os.path.join(os.path.expanduser("~"), ".ipm")) | ||
with open(config_file, "w") as f: | ||
json.dump(data, f) | ||
|
||
config = load_last_check() | ||
last_check = config.get('last_check') | ||
last_check = config.get("last_check") | ||
|
||
if last_check: | ||
last_check_date = datetime.strptime(last_check, '%Y-%m-%d') | ||
last_check_date = datetime.strptime(last_check, "%Y-%m-%d") | ||
if datetime.now() - last_check_date < timedelta(days=1): | ||
return | ||
|
||
try: | ||
response = requests.get(f'https://pypi.org/pypi/{package_name}/json') | ||
response = requests.get(f"https://pypi.org/pypi/{package_name}/json") | ||
response.raise_for_status() | ||
latest_version = response.json()['info']['version'] | ||
latest_version = response.json()["info"]["version"] | ||
|
||
if current_version < latest_version: | ||
logger.print_warn(f"A new version ({latest_version}) of {package_name} is available. " | ||
f"You're using version {current_version}. Please update using 'pip install --upgrade {package_name}'.") | ||
if __version__ < latest_version: | ||
logger.print_warn( | ||
f"A new version ({latest_version}) of {package_name} is available. " | ||
f"You're using version {__version__}. Please update using 'pip install --upgrade {package_name}'." | ||
) | ||
|
||
config['last_check'] = datetime.now().strftime('%Y-%m-%d') | ||
config["last_check"] = datetime.now().strftime("%Y-%m-%d") | ||
save_last_check(config) | ||
except requests.exceptions.RequestException as e: | ||
logger.print_err(f"Could not check for updates: {e}") | ||
logger.print_err(f"Could not check for updates: {e}") |
Oops, something went wrong.