/
channel_installer.py
1920 lines (1348 loc) · 78.7 KB
/
channel_installer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# These lines allow to use UTF-8 encoding and run this file with `./update.py`, instead of `python update.py`
# https://stackoverflow.com/questions/7670303/purpose-of-usr-bin-python3
# https://stackoverflow.com/questions/728891/correct-way-to-define-python-source-code-encoding
#
#
#
# Licensing
#
# Channel Manager Installer, install channel packages
# Copyright (C) 2017 Evandro Coan <https://github.com/evandrocoan>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or ( at
# your option ) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import sublime
import sublime_plugin
import os
import re
import sys
import time
import shutil
import io
import json
import shlex
import threading
import configparser
g_is_running = False
g_installer_thread = None
g_is_package_control_installed = False
# How many packages to ignore and unignore in batch to fix the ignored packages bug error
PACKAGES_COUNT_TO_IGNORE_AHEAD = 8
# The minimum time between multiple calls setting the `ignored_packages` setting, without triggering
# the Sublime Text error `It appears a package is trying to ignore itself, causing a loop`
IGNORE_PACKAGE_MINIMUM_WAIT_TIME = 1.7
CLEAN_PACKAGESMANAGER_FLAG = 1
RESTORE_REMOVE_ORPHANED_FLAG = 2
ALL_RUNNING_CONTROL_FLAGS = CLEAN_PACKAGESMANAGER_FLAG | RESTORE_REMOVE_ORPHANED_FLAG
from collections import OrderedDict
from debug_tools.estimated_time_left import sequence_timer
from debug_tools.estimated_time_left import progress_info
from debug_tools.estimated_time_left import CurrentUpdateProgress
from . import settings as g_settings
from .channel_utilities import add_item_if_not_exists
from .channel_utilities import remove_item_if_exists
from .channel_utilities import convert_to_unix_path
from .channel_utilities import wrap_text
from .channel_utilities import is_directory_empty
from .channel_utilities import get_installed_packages
from .channel_utilities import unique_list_join
from .channel_utilities import unique_list_append
from .channel_utilities import load_data_file
from .channel_utilities import write_data_file
from .channel_utilities import string_convert_list
from .channel_utilities import get_main_directory
from .channel_utilities import remove_if_exists
from .channel_utilities import delete_read_only_file
from .channel_utilities import _delete_read_only_file
from .channel_utilities import wrap_text
from .channel_utilities import safe_remove
from .channel_utilities import remove_only_if_exists
from .channel_utilities import InstallationCancelled
from .channel_utilities import NoPackagesAvailable
from .channel_utilities import load_repository_file
from .channel_utilities import is_channel_upgraded
from .channel_utilities import recursively_delete_empty_folders
from .channel_utilities import print_failed_repositories
from .channel_utilities import sort_dictionary
from .channel_utilities import add_path_if_not_exists
from .channel_utilities import is_dependency
from .channel_utilities import is_package_dependency
from .channel_utilities import remove_git_folder
from .channel_utilities import add_git_folder_by_file
# When there is an ImportError, means that Package Control is installed instead of PackagesManager,
# or vice-versa. Which means we cannot do nothing as this is only compatible with PackagesManager.
try:
from package_control import cmd
g_is_package_control_installed = True
from package_control.package_manager import PackageManager
from package_control.package_disabler import PackageDisabler
from package_control.thread_progress import ThreadProgress
from package_control.commands.advanced_install_package_command import AdvancedInstallPackageThread
def silence_error_message_box(value):
pass
except ImportError:
from PackagesManager.package_control import cmd
from PackagesManager.package_control.show_error import silence_error_message_box
from PackagesManager.package_control.package_manager import PackageManager
from PackagesManager.package_control.package_disabler import PackageDisabler
from PackagesManager.package_control.thread_progress import ThreadProgress
from PackagesManager.package_control.commands.advanced_install_package_command import AdvancedInstallPackageThread
from debug_tools import getLogger
# Debugger settings: 0 - disabled, 127 - enabled
log = getLogger( 127, __name__ )
def _grade():
return 1 & ( not IS_UPDATE_INSTALLATION )
old_error_message = sublime.error_message
def silent_error_message(string):
log(1, "Sublime Error Message: \n%s", string)
# log( 2, "..." )
# log( 2, "..." )
# log( 2, "Debugging" )
# log( 2, "PACKAGE_ROOT_DIRECTORY: " + g_settings.PACKAGE_ROOT_DIRECTORY )
def main(channel_settings, is_forced=False):
"""
Before calling this installer, the `Package Control` user settings file, must have the
Channel file set before the default channel key `channels`.
Also the current `Package Control` cache must be cleaned, ensuring it is downloading and
using the Channel repositories/channel list.
"""
global g_installer_thread
# We can only run this when we are using the stable version of the channel. And when there is
# not a `.git` folder, we are running the `Development Version` of the channel.
main_git_path = os.path.join( g_settings.PACKAGE_ROOT_DIRECTORY, ".git" )
# Not attempt to run when we are running from outside a `.sublime-package` as the upgrader is
# only available for the `Stable Version` of the channel. The `Development Version` must use
# git itself to install or remove packages.
if is_forced or not os.path.exists( main_git_path ) and is_channel_upgraded( channel_settings ):
log( 1, "Entering on %s main(0)" % g_settings.CURRENT_PACKAGE_NAME )
g_installer_thread = ChannelInstaller( channel_settings )
g_installer_thread.start()
return g_installer_thread
class ChannelInstaller(threading.Thread):
def __init__(self, channel_settings):
threading.Thread.__init__(self)
self.channelName = channel_settings['CHANNEL_PACKAGE_NAME']
self.wasCancelled = False
self.channelSettings = channel_settings
self.package_manager = PackageManager()
self.package_disabler = PackageDisabler()
self.isExceptionRaised = False
self.failedRepositories = []
self.commandLineInterface = cmd.Cli( None, True )
self.uningoredPackagesToFlush = 0
self.ensure_packages_manager_on_last_positoin()
def _setupData(self):
global IS_UPDATE_INSTALLATION
self.isDevelopment = self.channelSettings['INSTALLATION_TYPE'] == "development"
if self.channelSettings['INSTALLER_TYPE'] == "installer":
self.isUpdateInstallation = self.channelSettings['INSTALLATION_TYPE'] == "upgrade"
self.setupInstaller()
else:
self.isUpdateInstallation = self.channelSettings['INSTALLATION_TYPE'] == "downgrade"
self.setupUninstaller()
IS_UPDATE_INSTALLATION = self.isUpdateInstallation
load_installation_settings_file( self )
if not self.isInstaller:
self.load_package_control_settings()
self.setup_packages_to_uninstall_last()
log( 1, "INSTALLER_TYPE: " + str( self.channelSettings['INSTALLER_TYPE'] ) )
log( 1, "INSTALLATION_TYPE: " + str( self.channelSettings['INSTALLATION_TYPE'] ) )
log( 1, "IS_UPDATE_INSTALLATION: " + str( IS_UPDATE_INSTALLATION ) )
def setupInstaller(self):
self.word_prefix = ""
self.word_Prefix = ""
self.word_install = "install"
self.word_Install = "Install"
self.word_installed = "installed"
self.word_Installed = "Installed"
self.word_installer = "installer"
self.word_Installer = "Installer"
self.word_installation = "installation"
self.word_Installation = "Installation"
self.install_message = "Select this to not install it."
self.uninstall_message = "Select this to install it."
self.isInstaller = True
self.installationType = "Upgrade" if self.isUpdateInstallation else "Installation"
self.installerMessage = "The %s was successfully installed." % self.installationType
self.notInstallMessage = "You must install it or cancel the %s." % self.installationType
self.setProgress = CurrentUpdateProgress( 'Installing the %s packages...' % self.installationType )
def packagesInformations():
return \
[
[ "Cancel the Installation Process", "Select this to cancel the %s process." % self.installationType ],
[ "Continue the Installation Process...", "Select this when you are finished selections packages." ]
]
self.packagesInformations = packagesInformations
def setupUninstaller(self):
self.word_prefix = "un"
self.word_Prefix = "Un"
self.word_install = "uninstall"
self.word_Install = "Uninstall"
self.word_installed = "uninstalled"
self.word_Installed = "Uninstalled"
self.word_installer = "uninstaller"
self.word_Installer = "Uninstaller"
self.word_installation = "uninstallation"
self.word_Installation = "Uninstallation"
self.install_message = "Select this to not uninstall it."
self.uninstall_message = "Select this to uninstall it."
self.isInstaller = False
self.installationType = "Downgrade" if self.isUpdateInstallation else "Uninstallation"
self.installerMessage = "The %s of %s was successfully completed." % ( self.installationType, self.channelName )
self.notInstallMessage = "You must uninstall it or cancel the %s." % self.installationType
self.setProgress = CurrentUpdateProgress( '%s of Sublime Text %s packages...' % ( self.installationType, self.channelName ) )
def packagesInformations():
return \
[
[ "Cancel the %s Process" % self.installationType, "Select this to cancel the %s process." % self.installationType ],
[ "Continue the %s Process..." % self.installationType, "Select this when you are finished selecting packages." ],
]
self.packagesInformations = packagesInformations
def update_user_channel_version(self):
packageChannelSettings = load_data_file( self.channelSettings['CHANNEL_PACKAGE_METADATA'] )
userChannelSettings = load_data_file( self.channelSettings['CHANNEL_INSTALLATION_DETAILS'] )
next_user_version = packageChannelSettings.get( 'version', '0.0.0' )
userChannelSettings['current_version'] = next_user_version
write_data_file( self.channelSettings['CHANNEL_INSTALLATION_DETAILS'], userChannelSettings )
def run(self):
"""
The installation is not complete when the user cancelled the installation process or
there are no packages available for an upgrade.
Python thread exit code
https://stackoverflow.com/questions/986616/python-thread-exit-code
"""
if is_allowed_to_run():
channelSettings = self.channelSettings
if channelSettings['INSTALLATION_TYPE'] == "upgrade":
channelSettings['INSTALLER_TYPE'] = "installer"
self._run()
channelSettings['INSTALLATION_TYPE'] = "downgrade"
channelSettings['INSTALLER_TYPE'] = "uninstaller"
self._run()
if not self.wasCancelled:
self.update_user_channel_version()
_unlock_installer( self, is_forced=True )
else:
self._run()
def _run(self):
self._setupData()
if self.isInstaller:
self.setupThread( self.installerProcedements )
else:
self.setupThread( self.uninstallerProcedements )
# Wait PackagesManager to load the found dependencies, before announcing it to the user
self.save_default_settings()
if not self.isExceptionRaised and not self.isUpdateInstallation:
sublime.set_timeout_async( self.check_installed_packages, 10000 )
sublime.set_timeout_async( self.check_installed_packages_alert, 1000 )
def setupThread(self, targetFunction):
try:
sublime.error_message = silent_error_message
ThreadProgress( self, self.setProgress, self.installerMessage )
targetFunction()
finally:
sublime.error_message = old_error_message
def installerProcedements(self):
log( _grade(), "Entering on %s run(1)" % self.__class__.__name__ )
self.gitExecutablePath = self.commandLineInterface.find_binary( "git.exe" if os.name == 'nt' else "git" )
log( _grade(), "run, gitExecutablePath: " + str( self.gitExecutablePath ) )
try:
self.install_modules()
except InstallationCancelled as error:
self.isExceptionRaised = True
self.wasCancelled = True
log( 1, str( error ) )
_unlock_installer( self )
except NoPackagesAvailable as error:
self.isExceptionRaised = True
log( 1, str( error ) )
_unlock_installer( self )
if not self.isUpdateInstallation:
self.uninstall_package_control()
def uninstallerProcedements(self):
log( _grade(), "Entering on %s run(1)" % self.__class__.__name__ )
try:
packages_to_uninstall = self.get_packages_to_uninstall( self.isUpdateInstallation )
non_packages_to_uninstall = self.get_non_packages_to_uninstall()
log( _grade(), "Packages to %s: " % self.installationType + str( packages_to_uninstall ) )
self.uninstall_packages( packages_to_uninstall, non_packages_to_uninstall )
if not self.isUpdateInstallation:
self.remove_channel()
self.uninstall_files()
self.uninstall_folders()
self.attempt_to_uninstall_packages_manager( packages_to_uninstall )
if not self.isUpdateInstallation:
self.uninstall_list_of_packages( [(self.channelSettings['CHANNEL_PACKAGE_NAME'], False)] )
except InstallationCancelled as error:
self.isExceptionRaised = True
self.wasCancelled = True
log( 1, str( error ) )
_unlock_installer( self )
except NoPackagesAvailable as error:
self.isExceptionRaised = True
log( 1, str( error ) )
_unlock_installer( self )
def install_modules(self):
if self.isDevelopment:
self.clone_sublime_text_channel()
non_packages_to_uninstall = self.get_non_packages_to_uninstall()
packages_to_install = self.get_development_packages()
self.install_development_packages( packages_to_install, non_packages_to_uninstall )
else:
packages_to_install = self.get_stable_packages()
self.install_stable_packages( packages_to_install )
def get_stable_packages(self):
"""
python ConfigParser: read configuration from string
https://stackoverflow.com/questions/27744058/python-configparser-read-configuration-from-string
"""
log( 2, "get_stable_packages, PACKAGES_TO_NOT_INSTALL_STABLE: " + str( self.channelSettings['PACKAGES_TO_NOT_INSTALL_STABLE'] ) )
channel_name = self.channelSettings['CHANNEL_PACKAGE_NAME']
current_index = 0
filtered_packages = []
installed_packages = get_installed_packages( exclusion_list=[channel_name] )
log( _grade(), "get_stable_packages, installed_packages: " + str( installed_packages ) )
# Do not try to install this own package and the Package Control, as they are currently running
currently_running = [ "Package Control", g_settings.CURRENT_PACKAGE_NAME, channel_name ]
packages_tonot_install = unique_list_join \
(
currently_running,
installed_packages,
g_packages_to_uninstall,
g_packages_not_installed if self.isUpdateInstallation else [],
self.channelSettings['PACKAGES_TO_NOT_INSTALL_STABLE'],
self.channelSettings['PACKAGES_TO_IGNORE_ON_DEVELOPMENT'],
)
packages_to_install = {}
install_exclusively = self.channelSettings['PACKAGES_TO_INSTALL_EXCLUSIVELY']
is_exclusively_install = len( install_exclusively )
repositories_loaded = load_repository_file( self.channelSettings['CHANNEL_REPOSITORY_FILE'], {} )
log( _grade(), "get_stable_packages, packages_tonot_install: " + str( packages_tonot_install ) )
if is_exclusively_install:
log( _grade(), "Performing exclusively installation of the packages: " + str( install_exclusively ) )
for package_name in repositories_loaded:
if package_name in install_exclusively:
packages_to_install[package_name] = repositories_loaded[package_name]
else:
packages_to_install = repositories_loaded
log( 2, "get_stable_packages, packages_to_install: %s" % [name for name in packages_to_install] )
for package_name in packages_to_install:
# # For quick testing
# current_index += 1
# if current_index > 7:
# break
if package_name not in packages_tonot_install \
and not is_dependency( package_name, packages_to_install ):
filtered_packages.append( package_name )
# When installing the channel, we must mark the packages already installed as packages which
# where not installed, so they are not uninstalled when the channel is uninstalled.
if not self.isUpdateInstallation \
and package_name in installed_packages:
g_packages_not_installed.append( package_name )
# return \
# [
# ('Active View Jump Back', False),
# ('amxmodx', False),
# ('Amxx Pawn', False),
# ('Clear Cursors Carets', False),
# ('Indent and braces', False),
# ('Invert Selection', False),
# ('PackagesManager', False),
# ('Toggle Words', False),
# # ('BBCode', False),
# ('DocBlockr', False),
# ('Gist', False),
# ('FileManager', False),
# ('FuzzyFileNav', False),
# ('ExportHtml', False),
# ('ExtendedTabSwitcher', False),
# ('BufferScroll', False),
# ('ChannelRepositoryTools', False),
# ('Better CoffeeScript', False),
# ]
if len( filtered_packages ) < 1:
raise NoPackagesAvailable( "There are 0 packages available to install!" )
if self.isUpdateInstallation:
log( 1, "New packages packages to install found... " + str( filtered_packages ) )
return filtered_packages
def install_stable_packages(self, packages_names):
"""
python multithreading wait till all threads finished
https://stackoverflow.com/questions/11968689/python-multithreading-wait-till-all-threads-finished
There is a bug with the AdvancedInstallPackageThread thread which trigger several errors of:
"It appears a package is trying to ignore itself, causing a loop.
Please resolve by removing the offending ignored_packages setting."
When trying to install several package at once, then here I am installing them one by one.
"""
self.set_default_settings( packages_names )
log( 2, "install_stable_packages, packages_names: " + str( packages_names ) )
# Package Control: Advanced Install Package
# https://github.com/wbond/package_control/issues/1191
# thread = AdvancedInstallPackageThread( packages_names )
# thread.start()
# thread.join()
current_index = 0
git_packages_count = len( packages_names )
for package_name, pi in sequence_timer( packages_names, info_frequency=0 ):
current_index += 1
progress = progress_info( pi, self.setProgress )
# # For quick testing
# if current_index > 3:
# break
log.newline( 2, count=2 )
log( 1, "%s Installing %d of %d: %s" % ( progress, current_index, git_packages_count, str( package_name ) ) )
self.ignore_next_packages( package_name, packages_names )
# We must to ignore it beforehand, otherwise it will start unignoring itself several times
if package_name == "PackagesManager":
self.setup_packages_ignored_list( ["Package Control", "0_package_control_loader"] )
if self.package_manager.install_package( package_name, False ) is False:
log( 1, "Error: Failed to install the repository `%s`!" % package_name )
self.failedRepositories.append( package_name )
else:
self.add_package_to_installation_list( package_name )
self.accumulative_unignore_user_packages( package_name )
self.accumulative_unignore_user_packages( flush_everything=True )
def get_non_packages_to_uninstall(self):
return self.download_not_packages_submodules( True )
def download_not_packages_submodules(self, only_list_packages=False):
log( 1, "download_not_packages_submodules..." )
non_packages_names = []
root = self.channelSettings['CHANNEL_ROOT_DIRECTORY']
log( 2, "download_not_packages_submodules, root: " + root )
gitFilePath = os.path.join( root, '.gitmodules' )
gitModulesFile = configparser.RawConfigParser()
current_index = 0
gitModulesFile.read( gitFilePath )
for section in gitModulesFile.sections():
url = gitModulesFile.get( section, "url" )
path = gitModulesFile.get( section, "path" )
# # For quick testing
# current_index += 1
# if current_index > 3:
# break
if 'Packages' != path[0:8]:
package_name = os.path.basename( path )
submodule_absolute_path = os.path.join( root, path )
log( 2, "download_not_packages_submodules, path: " + path )
if only_list_packages:
non_packages_names.append( package_name )
else:
if is_directory_empty( submodule_absolute_path ):
log.newline( count=2 )
log( 1, "Installing: %s" % ( str( url ) ) )
non_packages_names.append( package_name )
command = shlex.split( '"%s" clone "%s" "%s"' % ( self.gitExecutablePath, url, path ) )
output = str( self.commandLineInterface.execute( command, cwd=root ) )
self.add_folders_and_files_for_removal( submodule_absolute_path, path )
log( 1, "download_not_packages_submodules, output: " + str( output ) )
self.save_default_settings()
return non_packages_names
def get_development_packages(self):
development_ignored = self.channelSettings['PACKAGES_TO_NOT_INSTALL_DEVELOPMENT']
log( 2, "get_development_packages, PACKAGES_TO_NOT_INSTALL_DEVELOPMENT: " + str( development_ignored ) )
gitFilePath = os.path.join( self.channelSettings['CHANNEL_ROOT_DIRECTORY'], '.gitmodules' )
gitModulesFile = configparser.RawConfigParser()
current_index = 0
installed_packages = get_installed_packages( exclusion_list=[self.channelName] )
packages_tonot_install = unique_list_join( development_ignored, installed_packages )
log( 2, "get_development_packages, packages_tonot_install: " + str( packages_tonot_install ) )
packages = []
gitModulesFile.read( gitFilePath )
for section in gitModulesFile.sections():
# # For quick testing
# current_index += 1
# if current_index > 3:
# break
url = gitModulesFile.get( section, "url" )
path = gitModulesFile.get( section, "path" )
log( 2, "get_development_packages, path: " + path )
if 'Packages' == path[0:8]:
package_name = os.path.basename( path )
if package_name not in packages_tonot_install :
packages.append( ( package_name, url, path ) )
# return \
# [
# ('Active View Jump Back', 'https://github.com/evandrocoan/SublimeActiveViewJumpBack', 'Packages/Active View Jump Back'),
# # ('amxmodx', 'https://github.com/evandrocoan/SublimeAMXX_Editor', 'Packages/amxmodx'),
# # ('All Autocomplete', 'https://github.com/evandrocoan/SublimeAllAutocomplete', 'Packages/All Autocomplete'),
# # ('Amxx Pawn', 'https://github.com/evandrocoan/SublimeAmxxPawn', 'Packages/Amxx Pawn'),
# # ('Clear Cursors Carets', 'https://github.com/evandrocoan/ClearCursorsCarets', 'Packages/Clear Cursors Carets'),
# # ('Notepad++ Color Scheme', 'https://github.com/evandrocoan/SublimeNotepadPlusPlusTheme', 'Packages/Notepad++ Color Scheme'),
# ('PackagesManager', 'https://github.com/evandrocoan/package_control', 'Packages/PackagesManager'),
# ('Toggle Words', 'https://github.com/evandrocoan/ToggleWords', 'Packages/Toggle Words'),
# ('User', 'https://github.com/evandrocoan/User', 'Packages/User'),
# ]
return packages
def clone_sublime_text_channel(self):
"""
Clone the main repository as `https://github.com/evandrocoan/SublimeTextStudio` and install
it on the Sublime Text Data folder.
"""
root = self.channelSettings['CHANNEL_ROOT_DIRECTORY']
main_git_folder = os.path.join( root, ".git" )
if os.path.exists( main_git_folder ):
log.newline( count=2 )
log( 1, "Error: The folder '%s' already exists.\nYou already has some custom channel git installation." % main_git_folder )
log.newline()
else:
temp = self.channelSettings['TEMPORARY_FOLDER_TO_USE']
channel_temporary_folder = os.path.join( root, temp )
self.download_main_repository( root, temp )
files, folders = self.copy_overrides( channel_temporary_folder, root )
shutil.rmtree( channel_temporary_folder, onerror=_delete_read_only_file )
unique_list_append( g_files_to_uninstall, files )
unique_list_append( g_folders_to_uninstall, folders )
self.save_default_settings()
def download_main_repository(self, root, temp):
log( 1, "download_main_repository..." )
url = self.channelSettings['CHANNEL_ROOT_URL']
log.newline( count=2 )
log( 1, "Installing: %s" % ( str( self.channelSettings['CHANNEL_ROOT_URL'] ) ) )
self.download_repository_to_folder( url, root, temp )
# Delete the empty folders created by git while cloning the main repository
channel_temporary_folder = os.path.join( root, temp )
recursively_delete_empty_folders( channel_temporary_folder )
def download_repository_to_folder(self, url, root, temp ):
channel_temporary_folder = os.path.join( root, temp )
if os.path.isdir( channel_temporary_folder ):
shutil.rmtree( channel_temporary_folder, onerror=_delete_read_only_file )
command = shlex.split( '"%s" clone "%s" "%s"' % ( self.gitExecutablePath, url, temp ) )
output = str( self.commandLineInterface.execute( command, cwd=root ) )
log( 1, "download_repository_to_folder, output: " + str( output ) )
def install_development_packages(self, packages_infos, non_packages_to_uninstall):
root = self.channelSettings['CHANNEL_ROOT_DIRECTORY']
temp = self.channelSettings['TEMPORARY_FOLDER_TO_USE']
packages_names = [ package_info[0] for package_info in packages_infos ]
channel_temporary_folder = os.path.join( root, temp )
self.set_default_settings( packages_names, packages_infos, non_packages_to_uninstall )
log( 2, "install_development_packages, packages_infos: " + str( packages_infos ) )
self.download_not_packages_submodules()
current_index = 0
git_packages_count = len( packages_infos )
for package_info, pi in sequence_timer( packages_infos, info_frequency=0 ):
current_index += 1
package_name, url, path = package_info
progress = progress_info( pi, self.setProgress )
submodule_absolute_path = os.path.join( root, path )
# # For quick testing
# if current_index > 3:
# break
log.newline( count=2 )
log( 1, "%s Installing %d of %d: %s" % ( progress, current_index, git_packages_count, str( package_name ) ) )
self.ignore_next_packages( package_name, packages_names )
# We must to ignore it beforehand, otherwise it will start unignoring itself several times
if package_name == "PackagesManager":
self.setup_packages_ignored_list( ["Package Control", "0_package_control_loader"] )
if os.path.exists( submodule_absolute_path ):
# Add the missing packages file into the existent packages folder, including the `.git` folder.
if self.package_manager.backup_package_dir( package_name ):
self.download_repository_to_folder( url, root, temp )
self.copy_overrides( channel_temporary_folder, submodule_absolute_path, move_files=True, is_to_replace=False )
else:
self.failedRepositories.append( package_name )
log( 1, "Error: Failed to backup and install the repository `%s`!" % package_name )
self.accumulative_unignore_user_packages( package_name )
continue
else:
command = shlex.split( '"%s" clone --recursive "%s" "%s"' % ( self.gitExecutablePath, url, path) )
result = self.commandLineInterface.execute( command, cwd=root )
if result is False:
self.failedRepositories.append( package_name )
log( 1, "Error: Failed to download the repository `%s`!" % package_name )
self.accumulative_unignore_user_packages( package_name )
continue
command = shlex.split( '"%s" checkout master' % ( self.gitExecutablePath ) )
output = str( result ) + "\n" + str( self.commandLineInterface.execute( command, cwd=os.path.join( root, path ) ) )
log( 1, "install_development_packages, output: " + str( output ) )
self.add_package_to_installation_list( package_name )
self.accumulative_unignore_user_packages( package_name )
self.accumulative_unignore_user_packages( flush_everything=True )
# Clean the temporary folder after the process has ended
shutil.rmtree( channel_temporary_folder, onerror=_delete_read_only_file )
def get_packages_to_uninstall(self, is_downgrade):
filtered_packages = []
last_packages = []
packages_to_uninstall = g_channelDetails.get( 'packages_to_uninstall', [] )
if is_downgrade:
repositories_loaded = set( load_repository_file( self.channelSettings['CHANNEL_REPOSITORY_FILE'], {} ) )
all_installed_packages = set( packages_to_uninstall + g_packages_not_installed )
install_exclusively = set( self.channelSettings['PACKAGES_TO_INSTALL_EXCLUSIVELY'] )
is_exclusively_install = len( install_exclusively )
if is_exclusively_install:
packages_to_uninstall = all_installed_packages - install_exclusively
else:
packages_to_uninstall = all_installed_packages - repositories_loaded
# Remove from the stable version the new packages added to the stable version ignore lists
if not self.isDevelopment:
packages_to_not_install_stable = set( self.channelSettings['PACKAGES_TO_NOT_INSTALL_STABLE'] )
packages_to_ignore_on_development = set( self.channelSettings['PACKAGES_TO_IGNORE_ON_DEVELOPMENT'] )
extra_packages_to_ignore = packages_to_not_install_stable | packages_to_ignore_on_development
to_remove = set()
# Only attempt to remove packages which were actually installed
for package_name in extra_packages_to_ignore:
if package_name not in all_installed_packages:
to_remove.add( package_name )
extra_packages_to_ignore = extra_packages_to_ignore - to_remove
packages_to_uninstall = packages_to_uninstall | extra_packages_to_ignore
for package_name in PACKAGES_TO_UNINSTALL_FIRST:
# Only merges the packages which are actually being uninstalled
if package_name in packages_to_uninstall:
filtered_packages.append( package_name )
for package_name in PACKAGES_TO_UNINSTALL_LAST:
# Only merges the packages which are actually being uninstalled
if package_name in packages_to_uninstall:
last_packages.append( package_name )
packages_to_uninstall.remove( package_name )
# Add the remaining packages after the packages to install first
for package_name in packages_to_uninstall:
if package_name not in filtered_packages:
filtered_packages.append( package_name )
# Finally add the last packages to the full list
unique_list_append( filtered_packages, last_packages )
if is_downgrade:
# Allow to uninstall only the channel package when there is no other packages installed
if len( filtered_packages ) < 1:
raise NoPackagesAvailable( "There are 0 packages available to uninstall!" )
log( 1, "New packages packages to uninstall found... " + str( filtered_packages ) )
return filtered_packages
def uninstall_packages(self, packages_names, non_packages_names):
self.ask_user_for_which_packages_to_install( packages_names, non_packages_names=non_packages_names )
all_packages, dependencies = self.get_installed_repositories()
current_index = 0
packages_count = len( packages_names )
for package_name, pi in sequence_timer( packages_names, info_frequency=0 ):
current_index += 1
progress = progress_info( pi, self.setProgress )
is_dependency = is_package_dependency( package_name, dependencies, all_packages )
log.newline( count=2 )
log( 1, "%s %s of %d of %d: %s (%s)" % ( progress, self.installationType,
current_index, packages_count, str( package_name ), str( is_dependency ) ) )
silence_error_message_box( 61.0 )
self.ignore_next_packages( package_name, packages_names )
if package_name == "User":
log( 1, "Warning: We cannot touch the `User` package as is it is now filled with new settings." )
self.failedRepositories.append( package_name )
self.remove_packages_from_list( package_name )
continue
if package_name in PACKAGES_TO_UNINSTALL_LATER:
log( 1, "Skipping the %s of `%s`..." % ( self.installationType, package_name ) )
log( 1, "This package will be handled later." )
self.accumulative_unignore_user_packages( package_name )
continue
if self.package_manager.remove_package( package_name, is_dependency ) is False:
log( 1, "Error: Failed to uninstall the repository `%s`!" % package_name )
self.failedRepositories.append( package_name )
if self.isUpdateInstallation:
self.remove_packages_from_list( package_name )
else:
self.remove_packages_from_list( package_name )
self.accumulative_unignore_user_packages( package_name )
self.accumulative_unignore_user_packages( flush_everything=True )
def get_installed_repositories(self):
dependencies = None
all_packages = None
if g_is_package_control_installed:
_dependencies = self.package_manager.list_dependencies()
dependencies = set( _dependencies )
all_packages = set( _dependencies + get_installed_packages( list_default_packages=True ) )
else:
dependencies = set( self.package_manager.list_dependencies() )
all_packages = set( self.package_manager.list_packages( list_everything=True ) )
return all_packages, dependencies
def uninstall_files(self):
git_folders = []
log.newline( count=2 )
log( 1, "%s of added files: %s" % ( self.installationType, str( g_files_to_uninstall ) ) )
for file in g_files_to_uninstall:
log( 1, "Uninstalling file: %s" % str( file ) )
file_absolute_path = os.path.join( self.channelSettings['CHANNEL_ROOT_DIRECTORY'], file )
safe_remove( file_absolute_path )
add_git_folder_by_file( file, git_folders )
log( 1, "Removing git_folders..." )
for git_folder in git_folders:
remove_git_folder( git_folder )
del g_files_to_uninstall[:]
self.save_default_settings()
def uninstall_folders(self):
log.newline( count=2 )
log( 1, "%s of added folders: %s" % ( self.installationType, str( g_folders_to_uninstall ) ) )
for folder in reversed( g_folders_to_uninstall ):
folders_not_empty = []
log( 1, "Uninstalling folder: %s" % str( folder ) )
folder_absolute_path = os.path.join( self.channelSettings['CHANNEL_ROOT_DIRECTORY'], folder )
recursively_delete_empty_folders( folder_absolute_path, folders_not_empty )
for folder in g_folders_to_uninstall:
folders_not_empty = []
log( 1, "Uninstalling folder: %s" % str( folder ) )
folder_absolute_path = os.path.join( self.channelSettings['CHANNEL_ROOT_DIRECTORY'], folder )
recursively_delete_empty_folders( folder_absolute_path, folders_not_empty )
for folder in g_folders_to_uninstall:
folders_not_empty = []
log( 1, "Uninstalling folder: %s" % str( folder ) )
folder_absolute_path = os.path.join( self.channelSettings['CHANNEL_ROOT_DIRECTORY'], folder )
recursively_delete_empty_folders( folder_absolute_path, folders_not_empty )
if len( folders_not_empty ) > 0:
log( 1, "The installed folder `%s` could not be removed because is it not empty." % folder_absolute_path )
log( 1, "Its files contents are: " + str( os.listdir( folder_absolute_path ) ) )
del g_folders_to_uninstall[:]
self.save_default_settings()
def uninstall_package_control(self):
"""
Uninstals package control only if PackagesManager was installed, otherwise the user will end
up with no package manager.
"""
log( 2, "uninstall_package_control, g_packages_to_uninstall: " + str( g_packages_to_uninstall ) )
# Only uninstall it, when `PackagesManager` was also installed
if "PackagesManager" in g_packages_to_uninstall:
# When PackagesManager is installed, it was must be the last package to be installed
# because as soon as it loads, it starts uninstalling the Package Control. Then we wait
# until it finishes this and delete the old Package Control settings