-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathZnunyGenerateFilelist.py
109 lines (73 loc) · 3.14 KB
/
ZnunyGenerateFilelist.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
import sublime
import sublime_plugin
import os
import re
from os import walk
class ZnunyGenerateFilelist(sublime_plugin.TextCommand):
def run(self, edit):
folders = self.view.window().folders()
if len(folders) > 1:
sublime.status_message('Showing folder selection.')
sublime.active_window().show_quick_panel(folders, self.folder_selected)
else:
self.generate_filelist(folders[0])
def folder_selected(self, index):
folders = self.view.window().folders()
self.generate_filelist(folders[index])
def generate_filelist(self, folder):
sublime.status_message('Getting content.')
view_content = self.view.substr(sublime.Region(0, self.view.size()))
sublime.status_message('Got content.')
m = re.search(r'<Framework[^>]*>([^<]+)', view_content)
sublime.status_message('Getting Framework version.')
if not m:
return
sublime.status_message('Got Framework version.')
exec_permission = '770'
regular_permission = '660'
files = []
for (dirpath, dirnames, filenames) in walk(folder):
sub_dir = dirpath
if (sub_dir != folder):
sub_dir = sub_dir.replace(folder + os.path.sep, '')
else:
sub_dir = ''
if re.search(r'^\.vscode', sub_dir):
continue
if re.search(r'^\.idea', sub_dir):
continue
if re.search(r'^\.git', sub_dir):
continue
if re.search(r'^doc', sub_dir):
continue
if re.search(r'^misc', sub_dir):
continue
for filename in filenames:
if re.search(r'^\.', filename):
continue
if re.search(r'^README\.md$', filename):
continue
if re.search(r'^LICENSE$', filename):
continue
if re.search(r'\.sopm$', filename):
continue
files.append(os.path.join(sub_dir, filename))
file_entry_template = ' <File Permission="{permission}" Location="{location}"/>'
filelist = []
for file_location in sorted(files, key=str.lower):
file_entry = file_entry_template
permission = regular_permission
if re.search(r'^bin/', file_location):
permission = exec_permission
if re.search(r'\.sh$', file_location):
permission = exec_permission
if os.path.sep != '/':
file_location = file_location.replace(os.path.sep, '/')
file_entry = file_entry.replace('{permission}', permission)
file_entry = file_entry.replace('{location}', file_location)
filelist.append(file_entry)
filelist_result = "\n".join(filelist)
self.view.run_command("znuny_insert_filelist", {"args": {'filelist': filelist_result}})
class ZnunyInsertFilelist(sublime_plugin.TextCommand):
def run(self, edit, args):
self.view.insert(edit, self.view.sel()[0].begin(), args['filelist'])