33
33
HOTKEYS_PREF = os .path .join (PREF_DIR , 'hotkeys.json' )
34
34
MAX_RECENT_FILES = 10
35
35
JSON_PREFS = [USER_PREFS_PATH , BREAKPOINT_FILE , SKIPPOINT_FILE , HOTKEYS_PREF ]
36
- UPGRADABLE_PREFS = []
37
- UPGRADE_PREFS_FROM_VERSION = - 1
38
36
broken_files = {}
39
37
40
38
@@ -50,15 +48,17 @@ def ensure_pref_dir_exists():
50
48
raise Exception ('Failed to generate user dir {}' + USER_DIR )
51
49
52
50
53
- def check_for_upgradable_prefs ():
51
+ def get_upgradable_prefs ():
54
52
"""
55
53
Identify preference files that can be safely upgraded
56
54
between major editor versions. Only existing preference files
57
55
from the nearest older version are copied; missing files are skipped
58
- without warnings.
56
+ without warnings. Returns a list of prefs that can upgrade and the
57
+ versio number they're coming from.
58
+ :returns: (list, int)
59
59
"""
60
- global UPGRADABLE_PREFS
61
- global UPGRADE_PREFS_FROM_VERSION
60
+ upgradable_prefs = []
61
+ upgrade_prefs_from_version = - 1
62
62
for pref_file in JSON_PREFS :
63
63
if os .path .isfile (pref_file ):
64
64
break
@@ -72,20 +72,22 @@ def check_for_upgradable_prefs():
72
72
if os .path .isfile (old_pref_file ):
73
73
# In the future if we change the structure of the json
74
74
# prefs we'll need a way to convert them or skip
75
- UPGRADABLE_PREFS .append (old_pref_file )
76
- if UPGRADABLE_PREFS :
77
- UPGRADE_PREFS_FROM_VERSION = dir_num
75
+ upgradable_prefs .append (old_pref_file )
76
+ if upgradable_prefs :
77
+ upgrade_prefs_from_version = dir_num
78
78
break
79
79
dir_num -= 1
80
+ return upgradable_prefs , upgrade_prefs_from_version
80
81
81
82
82
- def upgrade_prefs ():
83
+ def upgrade_prefs (prefs_to_upgrade ):
83
84
"""
84
85
Copies old 'upgradeable' prefs to current pref dir, will eat and
85
86
exception raised by shutil.copy. In the future this function may do more
86
87
than simply copy.
88
+ :param prefs_to_upgrade: List of pref filepaths to upgrade
87
89
"""
88
- for pref_file in UPGRADABLE_PREFS :
90
+ for pref_file in prefs_to_upgrade :
89
91
try :
90
92
shutil .copy (pref_file , PREF_DIR )
91
93
except Exception as e :
@@ -94,7 +96,8 @@ def upgrade_prefs():
94
96
95
97
96
98
ensure_pref_dir_exists ()
97
- check_for_upgradable_prefs ()
99
+ # Must check these before we setup the defaults at the bottom of this file
100
+ UPGRADABLE_PREFS , UPGRADE_PREFS_FROM_VERSION = get_upgradable_prefs ()
98
101
99
102
100
103
class USER_PREF ():
0 commit comments