GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (fd87bb)
by thatsIch
01:20
created

on_zip_path_entered()   B

Complexity

Conditions 6

Size

Total Lines 26

Duplication

Lines 26
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
c 1
b 0
f 0
dl 26
loc 26
rs 7.5384
1
import os.path
2
# import shutil
3
# import tempfile
4
# import zipfile
5
6
import sublime
7
import sublime_plugin
8
9
# from .logger import info, error
10
11
from .http.online_checker import is_gh_online
12
# from .http.content_downloader import download_from_to
13
from .install import folder
14
from .install import from_zip
15
# from .path.skin_path_provider import get_cached_skin_path
16
17
18
GITHUB_ACCESS_TOKEN = "3e2e92777aab20a3352c058f9a8eb10e5ff5fd61"
19
20
21
# def install_zip_into_skins_folder(zip_file):
22
#     with zipfile.ZipFile(zip_file) as zipped_skin:
23
#         skins_path = get_cached_skin_path()
24
#         info("Found skins path in '" + skins_path + "'.")
25
26
#         zip_name = zip_file.rsplit('/', 1)[-1]
27
28
#         folder_name, dummy_ext = os.path.splitext(zip_name)
29
#         info("Skin folder name will be '" + folder_name + "'.")
30
31
#         skin_path = os.path.join(skins_path, folder_name)
32
#         skin_path = minify_folder(skin_path)
33
#         info("Extracting zip from '" + zip_file + "' to '" + skin_path + "'.")
34
35
#         zipped_skin.extractall(skin_path)
36
37
#         sublime.message_dialog("Successfully installed skin into '" + skin_path + "'!")
38
39
#         return True
40
41
42
# def minify_folder(folder_path):
43
#     """
44
#     Reduce unnecessary depth of folder structures for skins.
45
46
#     If you install a skin via a ZIP if could be that in the zip
47
#     an additional folder is already wrapped around like via Github
48
#     and thus we can remove that layer to reduce the depth to the real skin files.
49
#     """
50
#     content_names = os.listdir(folder_path)
51
#     while len(content_names) == 1:
52
#         content_path = os.path.join(folder_path, content_names[0])
53
54
#         if os.path.isdir(content_path):
55
#             content_paths = [os.path.join(content_path, file_name) for file_name in os.listdir(content_path)]
56
57
#             for f in content_paths:
58
#                 shutil.move(f, folder_path)
59
60
#             os.rmdir(content_path)
61
62
#         # reset for while recursion
63
#         content_names = os.listdir(folder_path)
64
65
#     return folder_path
66
67
68
# def count_folders_in_folder(folder_path):
69
#     """Non-recursive version of os.walk for directories."""
70
#     return sum(os.path.isdir(os.path.join(folder_path, f)) for f in os.listdir(folder_path))
71
72
73
# def count_files_in_folder(folder_path):
74
#     """Non-recursive version of os.walk for files."""
75
#     return sum(os.path.isfile(os.path.join(folder_path, f)) for f in os.listdir(folder_path))
76
77
78
# class InstallSkinCommand(sublime_plugin.ApplicationCommand):
79
80
#     def run(self):
81
#         """
82
#         Could install from direct repo URL, zip file or github release or even branch."""
83
#         pass
84
85
86
# class RainmeterInstallSkinFromZipCommand(sublime_plugin.ApplicationCommand):
87
88
#     def on_zipped_skin_url_entered(self, url):
89
#         info("Found url '" + url + "' of zip.")
90
#         sublime.set_timeout_async(lambda: self.on_zipped_skin_url_entered_async(url), 0)
91
92
#     def on_zipped_skin_url_entered_async(self, url):
93
#         with tempfile.TemporaryDirectory() as temp_path:
94
#             info("Downloading zip to temp folder '" + temp_path + "'.")
95
#             zip_name = url.rsplit('/', 1)[-1]
96
97
#             temp_file = os.path.join(temp_path, zip_name)
98
#             download_from_to(url, temp_file)
99
#             info("Downloaded zip to temp file '" + temp_file + "'.")
100
101
#             if not zipfile.is_zipfile(temp_file):
102
#                 message = "The file from '" + url + "' is not a valid ZIP file. Invalid files can not be extracted. Aborting Operation."
103
104
#                 error(message)
105
#                 sublime.error_message(message)
106
107
#                 return False
108
109
#             return install_zip_into_skins_folder(temp_file)
110
111
#     def run(self):
112
#         maybe_clipboard = sublime.get_clipboard()
113
#         default_url = maybe_clipboard if maybe_clipboard else "https://skin.zip"
114
115
#         sublime.active_window().show_input_panel(
116
#             "Enter URL to zipped Skin:",
117
#             default_url,
118
#             self.on_zipped_skin_url_entered, None, None
119
#         )
120
121
122
# class InstallSkinFromGithubCommand(sublime_plugin.ApplicationCommand):
123
124
#     def on_github_skin_url_entered(self, url):
125
#         # skin_path = get_cached_skin_path()
126
127
#         with tempfile.TemporaryDirectory() as temp_path:
128
#             zip_name = url.rsplit('/', 1)[-1]
129
130
#             temp_file = os.path.join(temp_path, zip_name)
131
#             download_from_to(url, temp_file)
132
#             print(temp_file)
133
134
#         print(url)
135
136
#     def run(self):
137
#         if not is_gh_online():
138
#             message = "Could not access github.com. Please check your connection and try again or look if github.com is down."
139
140
#             error(message)
141
#             sublime.error_message(message)
142
143
#         sublime.active_window().show_input_panel(
144
#             "Enter Github Project URL to Rainmeter Skin:",
145
#             "https://github.com/<user>/<project>",
146
#             self.on_github_skin_url_entered, None, None
147
#         )
148
149
150 View Code Duplication
class RainmeterInstallSkinFromFolderCommand(sublime_plugin.ApplicationCommand):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
151
152
    def run(self):
153
        # check cache first to determine the default path shown to the user
154
        install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_folder.cache")
155
        if os.path.exists(install_cache_path) and os.path.isfile(install_cache_path):
156
            with open(install_cache_path, 'r') as cache_handler:
157
                cache_content = cache_handler.read()
158
                default_path = cache_content
159
160
        else:
161
            user = os.path.expanduser("~")
162
            downloads = os.path.join(user, "Downloads")
163
164
            if os.path.exists(downloads) and os.path.isdir(downloads):
165
                default_path = downloads
166
            else:
167
                default_path = None
168
169
        sublime.active_window().show_input_panel(
170
            "Enter skin folder location:",
171
            default_path,
172
            self.on_folder_path_entered, None, None
173
        )
174
175
    def on_folder_path_entered(self, path):
176
        if not os.path.exists(path):
177
            sublime.error_message("The entered path '" + path + "' is not valid. Please check your input.")
178
            return
179
180
        if not os.path.isdir(path):
181
            sublime.error_message("The entered path '" + path + "' is not a directory. Please check your input.")
182
            return
183
184
        if not folder.find_inis_in_folder(path):
185
            sublime.error_message("The entered path '" + path + "' is not a valid Rainmeter skin. Please check your input.")
186
            return
187
188
        # we expect the user to enter a new path which we need to persist
189
        install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_folder.cache")
190
        if os.path.exists(install_cache_path):
191
            write_mode = 'w'
192
        else:
193
            write_mode = 'x'
194
            os.makedirs(os.path.dirname(install_cache_path))
195
196
        with open(install_cache_path, write_mode) as cache_handler:
197
            cache_handler.write(path)
198
199
        dest_folder = folder.install_skin_folder_into_skins_folder(path)
200
        sublime.message_dialog("Skin was successfully installed into \n\n" + dest_folder)
201
202
203 View Code Duplication
class RainmeterInstallSkinFromZipCommand(sublime_plugin.ApplicationCommand):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
204
205
    def run(self):
206
        # check cache first to determine the default path shown to the user
207
        install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_zip.cache")
208
        if os.path.exists(install_cache_path) and os.path.isfile(install_cache_path):
209
            with open(install_cache_path, 'r') as cache_handler:
210
                cache_content = cache_handler.read()
211
                default_path = cache_content
212
213
        else:
214
            # show some default location from which the user can search from
215
            user = os.path.expanduser("~")
216
            downloads = os.path.join(user, "Downloads")
217
218
            if os.path.exists(downloads) and os.path.isdir(downloads):
219
                default_path = downloads
220
            else:
221
                default_path = None
222
223
        sublime.active_window().show_input_panel(
224
            "Enter skin zip location:",
225
            default_path,
226
            self.on_zip_path_entered, None, None
227
        )
228
229
    def on_zip_path_entered(self, path):
230
        if not os.path.exists(path):
231
            sublime.error_message("The entered path '" + path + "' is not valid. Please check your input.")
232
            return
233
234
        if not os.path.isfile(path):
235
            sublime.error_message("The entered path '" + path + "' is not a file. Please check your input.")
236
            return
237
238
        if not path.endswith(".zip"):
239
            sublime.error_message("The entered path '" + path + "' is not a zip file. Please check your input.")
240
            return
241
242
        # we expect the user to enter a new path which we need to persist
243
        install_cache_path = os.path.join(sublime.cache_path(), "Rainmeter", "install", "last_entered_zip.cache")
244
        if os.path.exists(install_cache_path):
245
            write_mode = 'w'
246
        else:
247
            write_mode = 'x'
248
            os.makedirs(os.path.dirname(install_cache_path))
249
250
        with open(install_cache_path, write_mode) as cache_handler:
251
            cache_handler.write(path)
252
253
        from_zip.install_skin_zip_into_skins_folder(path)
254
        sublime.status_message("Skin was successfully installed!")
255
256
257
class RainmeterInstallSkinFromGitCommand(sublime_plugin.ApplicationCommand):
258
259
    def run(self):
260
        pass
261
262
    def on_git_path_entered(self, path):
263
        pass
264
265
266
class RainmeterInstallSkinFromGithubCommand(sublime_plugin.ApplicationCommand):
267
268
    def run(self):
269
        pass
270
271
    def on_github_path_entered(self, path):
272
        pass
273