This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
ModeCss.py
69 lines (61 loc) · 1.95 KB
/
ModeCss.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
# -*- coding: utf-8 -*-
import sublime, sublime_plugin
import locale
import os, glob, re,sys
ST2 = sys.version_info < (3, 0)
if ST2:
import Lib
else:
import modeCSS.Lib
class ModeCssCommand(sublime_plugin.TextCommand):
'''项目模块管理'''
def on_done(self, path):
'''取得项目路径'''
try:
if path:
global files
files = self.get_project_files(self, path)
except:
pass
def get_project_files(self, edit, path):
'''读取项目文件列表'''
if os.path.isdir(path):
dirs_ = os.listdir(path) # 取得目录文件列表
_files_ = self.getFiles(path) # 取得目录中的文件
for name in dirs_:
dir = path + '/' + name + '/'
if os.path.isdir(dir): # 如果是目录,递归读取
_files_ += self.get_project_files(self, dir)
return _files_
else:
pass
def getFiles(self, path):
'''读取文件列表'''
import glob
processed = settings.get("processed_lists") or [] # 读取设置
_files_ = []
if processed :
for n in processed:
_files_ += glob.glob(path + "\\" + n) # 取得目录中的文件
return _files_
else:
pass
def readFile(self, path):
'''读取文件内容'''
if os.path.isfile(path):
# 如果是文件,执行以下内容
# import chardet
with open(path) as f:
content = f.readline()
# chardet.detect(content)
for line in content:
print(line)
pass
def run(self, edit):
view = self.view
sel = view.sel()
view.window().show_input_panel("project path:", "", self.on_done, None, None)
print(files)
if files:
for n in files:
self.readFile(n)