Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
More messages and better dialogs content #31
Browse files Browse the repository at this point in the history
  • Loading branch information
zrzka committed Oct 26, 2017
1 parent baf7462 commit bf2d57a
Showing 1 changed file with 39 additions and 17 deletions.
56 changes: 39 additions & 17 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
_cleanup_paths = []


def _get_version(release):
version = release['tag_name']
if version.startswith('v'):
version = version[1:]
return version


def _cleanup():
global _cleanup_paths

Expand Down Expand Up @@ -202,24 +209,38 @@ def _move_to_site_packages(extracted_zip_dir):
def _local_installation_exists(release):
_info('Checking Black Mamba installation...')

if os.path.exists(os.path.join(_TARGET_DIR, '.git')):
_terminate('Skipping, Black Mamba GitHub repository detected, use git pull')
if os.path.islink(_TARGET_DIR):
_terminate('Skipping, Black Mamba symlinked to site-packages-3')

local_version = None
try:
import blackmamba
local_version = blackmamba.__version__
_info('Black Mamba {} installed'.format(local_version))

except ModuleNotFoundError:
_info('Black Mamba not installed')

exists = os.path.exists(_TARGET_DIR)
if local_version is not None:
remote_version = _get_version(release)

if exists:
try:
console.alert('Black Mamba Installer',
'Black Mamba is already installed. Do you want to replace it with {}?'.format(release['tag_name']),
'Replace')
if remote_version == local_version:
console.alert(
'Black Mamba Installer',
'Black Mamba {} installed. Do you want to replace it with {}?'.format(local_version, remote_version),
'Replace'
)
else:
console.alert(
'Black Mamba Installer',
'Black Mamba {} installed. Do you want to update it to {}?'.format(local_version, remote_version),
'Update'
)

except KeyboardInterrupt:
_terminate('Cancelling installation on user request')

if exists:
_info('Black Mamba installed, will be replaced')

return exists


def _save_release_info(release):
_info('Saving installed version release info')
Expand All @@ -243,12 +264,13 @@ def _install(prerelease=False):
_move_to_site_packages(extracted_zip_dir)
_save_release_info(release)
_cleanup()
_info('Black Mamba {} installed'.format(release['tag_name']))
_info('Black Mamba {} installed'.format(_get_version(release)))

tag_name = release['tag_name']
console.alert('Black Mamba Installer',
'Black Mamba {} installed.\n\nPythonista RESTART needed for updates to take effect.'.format(tag_name),
'Got it!', hide_cancel_button=True)
console.alert(
'Black Mamba {} Installed'.format(_get_version(release)),
'Pythonista RESTART is required for changes to take effect.',
'Got it!', hide_cancel_button=True
)


if __name__ == '__main__':
Expand Down

0 comments on commit bf2d57a

Please sign in to comment.