33
33
input = raw_input
34
34
35
35
36
+ EBCLI_INSTALLER_STAMP = '.ebcli_installer_stamp'
37
+
38
+
36
39
EXECUTABLE_WRAPPERS = {
37
40
'bat' : '\n ' .join (
38
41
[
@@ -378,6 +381,15 @@ def _create_virtualenv(
378
381
of execution of this script and now
379
382
- this script was executed with a Python executable not in PATH
380
383
384
+ Prior to creation of the virtualenv, this function checks whether
385
+ one by name `.ebcli-virtual-env` already exists. If this directory
386
+ was not created by this installer, installation halts and the user
387
+ is asked to either delete the directory or to specify an alternate
388
+ location using the `--location` argument of this script.
389
+
390
+ In all other cases, `.ebcli-virtual-env` is (re)created and a file
391
+ to denote that the installer created `.ebcli-virtual-env` is added.
392
+
381
393
:param virtualenv_executable: the name of the virtualenv executable
382
394
:param virtualenv_location: the relative or absolute path to the location
383
395
where the virtualenv, ".ebcli-virtual-env", must
@@ -392,10 +404,29 @@ def _create_virtualenv(
392
404
virtualenv, ".ebcli-virtual-env", was created.
393
405
"""
394
406
virtualenv_location = virtualenv_location or _user_local_directory ()
407
+ virtualenv_directory = os .path .join (virtualenv_location , VIRTUALENV_DIR_NAME )
408
+
409
+ if (
410
+ os .path .exists (virtualenv_directory )
411
+ and not _directory_was_created_by_installer (virtualenv_directory )
412
+ ):
413
+ _error (
414
+ 'Installation cannot proceed because "{virtualenv_location}" already exists '
415
+ 'but was not created by this EBCLI installer.'
416
+ '\n '
417
+ '\n '
418
+ 'You can either:\n '
419
+ '\n '
420
+ '1. Delete "{virtualenv_location}" after verifying you don\' t need it; OR\n '
421
+ '2. Specify an alternate location to install the EBCLI and its artifacts in '
422
+ 'using the `--location` argument of this script .\n ' .format (
423
+ virtualenv_location = virtualenv_directory
424
+ )
425
+ )
395
426
396
427
virtualenv_args = [
397
428
virtualenv_executable ,
398
- os . path . join ( virtualenv_location , VIRTUALENV_DIR_NAME )
429
+ virtualenv_directory
399
430
]
400
431
401
432
python_installation and virtualenv_args .extend (
@@ -405,6 +436,8 @@ def _create_virtualenv(
405
436
if _exec_cmd (virtualenv_args , quiet ) != 0 :
406
437
exit (1 )
407
438
439
+ _add_ebcli_stamp (virtualenv_directory )
440
+
408
441
return virtualenv_location
409
442
410
443
@@ -502,6 +535,26 @@ def _install_ebcli(quiet, version, ebcli_source):
502
535
_exec_cmd (install_args , quiet )
503
536
504
537
538
+ def _add_ebcli_stamp (virtualenv_directory ):
539
+ """
540
+ Function adds a stamp in the form of a file, `EBCLI_INSTALLER_STAMP`
541
+ to recognize during future executions of this script that it created
542
+ it.
543
+
544
+ :param virtualenv_directory: The directory where the EBCLI and its artifacts
545
+ will be installed
546
+ :return: None
547
+ """
548
+ with open (
549
+ os .path .join (
550
+ virtualenv_directory ,
551
+ EBCLI_INSTALLER_STAMP
552
+ ),
553
+ 'w'
554
+ ) as file :
555
+ file .write ('\n ' )
556
+
557
+
505
558
def _bat_script_body (virtualenv_location ):
506
559
"""
507
560
Function returns a CMD Prompt (bat) script which essentially will
@@ -517,6 +570,24 @@ def _bat_script_body(virtualenv_location):
517
570
)
518
571
519
572
573
+ def _directory_was_created_by_installer (virtualenv_directory ):
574
+ """
575
+ Function checks whether `virtualenv_directory` was previously created
576
+ by this script.
577
+
578
+ :param virtualenv_directory: The directory where the EBCLI and its
579
+ artifacts will be installed.
580
+ :return: Boolean indicating whether `virtualenv_directory` was created
581
+ by this script or not.
582
+ """
583
+ return os .path .exists (
584
+ os .path .join (
585
+ virtualenv_directory ,
586
+ EBCLI_INSTALLER_STAMP
587
+ )
588
+ )
589
+
590
+
520
591
def _eb_wrapper_location (virtualenv_location ):
521
592
"""
522
593
Function returns the location of the directory within the virtualenv,
0 commit comments