returns a dictionary containing the ArchiveBox GitHub release info for the recommended upgrade version and the currently installed version
(config)
| 422 | return datetime.fromtimestamp(src_last_modified_unix_timestamp).strftime('%Y-%m-%d %H:%M:%S %s') |
| 423 | |
| 424 | def get_versions_available_on_github(config): |
| 425 | """ |
| 426 | returns a dictionary containing the ArchiveBox GitHub release info for |
| 427 | the recommended upgrade version and the currently installed version |
| 428 | """ |
| 429 | |
| 430 | # we only want to perform the (relatively expensive) check for new versions |
| 431 | # when its most relevant, e.g. when the user runs a long-running command |
| 432 | subcommand_run_by_user = sys.argv[3] if len(sys.argv) > 3 else 'help' |
| 433 | long_running_commands = ('add', 'schedule', 'update', 'status', 'server') |
| 434 | if subcommand_run_by_user not in long_running_commands: |
| 435 | return None |
| 436 | |
| 437 | github_releases_api = "https://api.github.com/repos/ArchiveBox/ArchiveBox/releases" |
| 438 | response = requests.get(github_releases_api) |
| 439 | if response.status_code != 200: |
| 440 | stderr(f'[!] Warning: GitHub API call to check for new ArchiveBox version failed! (status={response.status_code})', color='lightyellow', config=config) |
| 441 | return None |
| 442 | all_releases = response.json() |
| 443 | |
| 444 | installed_version = parse_version_string(config['VERSION']) |
| 445 | |
| 446 | # find current version or nearest older version (to link to) |
| 447 | current_version = None |
| 448 | for idx, release in enumerate(all_releases): |
| 449 | release_version = parse_version_string(release['tag_name']) |
| 450 | if release_version <= installed_version: |
| 451 | current_version = release |
| 452 | break |
| 453 | |
| 454 | current_version = current_version or all_releases[-1] |
| 455 | |
| 456 | # recommended version is whatever comes after current_version in the release list |
| 457 | # (perhaps too conservative to only recommend upgrading one version at a time, but it's safest) |
| 458 | try: |
| 459 | recommended_version = all_releases[idx+1] |
| 460 | except IndexError: |
| 461 | recommended_version = None |
| 462 | |
| 463 | return {'recommended_version': recommended_version, 'current_version': current_version} |
| 464 | |
| 465 | def can_upgrade(config): |
| 466 | if config['VERSIONS_AVAILABLE'] and config['VERSIONS_AVAILABLE']['recommended_version']: |
no test coverage detected