Skip to content

Commit 218b3fd

Browse files
committed
Correct python typo for data structure
2 parents b3f8af6 + 6d8c780 commit 218b3fd

34 files changed

+2491
-1805
lines changed

.travis.yml

+20-28
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
language: python3
2-
sudo: required
3-
python:
4-
- "3.6"
1+
language: python
2+
python: "3.6"
53

6-
notifications:
7-
email:
8-
recipients:
9-
- zhuheqin1@gmail.com
10-
on_success: change # default: change
11-
on_failure: always # default: always
4+
branches:
5+
only:
6+
- master
7+
8+
env:
9+
# Github Pages
10+
- GH_REF: github.com/USTC-Resource/USTC-Course
1211

1312
install:
14-
- sudo apt-get install python3 -y
15-
- sudo apt-get install python3-pip -y
16-
- sudo pip3 install markdown
17-
- sudo pip3 install pypinyin
13+
- pip install --upgrade pip
14+
- pip install flake8 markdown pypinyin
1815

1916
script:
20-
- python3 utils/genReadme.py
21-
- python3 utils/genIndex.py
17+
- flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
18+
- python utils/genReadme.py
19+
- python utils/genIndex.py
2220

2321
after_script:
2422
# Build Master Repository(Coding Pages)
@@ -31,15 +29,9 @@ after_script:
3129
- git commit -m "Travis-CI Update pages with build $TRAVIS_BUILD_NUMBER"
3230
- git push -f "https://${GH_TOKEN}@${GH_REF}" master:gh-pages
3331

34-
addons:
35-
apt:
36-
update: true
37-
38-
branches:
39-
only:
40-
- master
41-
env:
42-
global:
43-
# Github Pages
44-
- GH_REF: github.com/USTC-Resource/USTC-Course
45-
32+
notifications:
33+
email:
34+
recipients:
35+
- zhuheqin1@gmail.com
36+
on_success: change # default: change
37+
on_failure: always # default: always

utils/checkBigFile.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,35 @@
44
import argparse
55

66
parser = argparse.ArgumentParser()
7-
parser.add_argument('-p','--path',help='path to check',default='.')
8-
parser.add_argument('-s','--size',help='max size of file to be removed',default=2**20*100) # 100Mb
7+
parser.add_argument('-p', '--path', help='path to check', default='.')
8+
parser.add_argument(
9+
'-s', '--size', help='max size of file to be removed',
10+
default=2**20 * 100) # 100Mb
911
args = parser.parse_args()
1012

1113
PATH = args.path
1214
SIZE = args.size
13-
def checkBigFile(path,size):
15+
16+
17+
def checkBigFile(path, size):
1418
big = '.bigFile'
1519
if not os.path.exists(big):
1620
os.mkdir(big)
1721
gen = os.walk(os.path.abspath(path))
18-
for path,dirs,files in gen:
22+
for path, dirs, files in gen:
1923
li = path.strip(os.sep).split(os.sep)
20-
if any([i[0]=='.' and i!='.' for i in li]):continue
24+
if any([i[0] == '.' and i != '.' for i in li]): continue
2125
for file in files:
22-
filePath = os.path.join(path,file)
26+
filePath = os.path.join(path, file)
2327
sz = os.path.getsize(filePath)
2428
if sz > size:
2529
print('[BIG]: {} is bigger than 100mb'.format(filePath))
2630
try:
27-
shutil.move(filePath,big)
31+
shutil.move(filePath, big)
2832
except Exception as e:
29-
print(e,path)
33+
print(e, path)
3034
os.remove(filePath)
31-
if __name__=='__main__':
32-
checkBigFile(PATH,SIZE)
35+
36+
37+
if __name__ == '__main__':
38+
checkBigFile(PATH, SIZE)

utils/codecogs.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,47 @@
33
import sys
44
from translate import Translator as TR
55

6-
FORMULA = re.compile(r'\${1,2}(?P<formula>.+?)\${1,2}',re.DOTALL)
6+
FORMULA = re.compile(r'\${1,2}(?P<formula>.+?)\${1,2}', re.DOTALL)
77
Chinese = re.compile(u"(?P<chinese>[\u4e00-\u9fa5]+)")
88
API = 'https://latex.codecogs.com/gif.latex?'
9+
10+
911
def codecog(f):
1012
if os.path.exists(f) and f.endswith('.md'):
1113
with open(f) as fp:
1214
txt = fp.read()
13-
with open(f,'w') as fp:
14-
fp.write(re.sub(FORMULA,covert,txt))
15+
with open(f, 'w') as fp:
16+
fp.write(re.sub(FORMULA, covert, txt))
1517
else:
16-
s = re.sub(FORMULA,covert,f)
18+
s = re.sub(FORMULA, covert, f)
1719
print(s)
20+
21+
1822
def covert(matched):
1923
s = matched.group('formula').strip('$ ')
20-
s = re.sub(Chinese,zh2en,s)
21-
s = re.sub(r'\r+|\n+|\\n',' ',s)
22-
s = re.sub(' +','&space;',s)
23-
return '![]({})'.format(API+s)
24+
s = re.sub(Chinese, zh2en, s)
25+
s = re.sub(r'\r+|\n+|\\n', ' ', s)
26+
s = re.sub(' +', '&space;', s)
27+
return '![]({})'.format(API + s)
28+
29+
2430
def zh2en(txt):
2531
s = txt.group('chinese').strip()
26-
tran = TR(to_lang='en',from_lang='zh')
32+
tran = TR(to_lang='en', from_lang='zh')
2733
en = tran.translate(s)
28-
return re.sub(' +','-',en)
34+
return re.sub(' +', '-', en)
35+
2936

3037
def handle(path):
3138
if os.path.isdir(path):
32-
for p,ds,fs in os.walk(path):
39+
for p, ds, fs in os.walk(path):
3340
for f in fs:
3441
if f.endswith('.md'):
35-
codecog(os.path.join(p,f))
42+
codecog(os.path.join(p, f))
3643
else:
3744
codecog(path)
3845

46+
3947
if __name__ == '__main__':
4048
args = sys.argv[1:]
4149
if not args:

utils/genReadme.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55

66
parser = ArgumentParser()
77

8-
parser.add_argument('-p','--path',default='.',help='path to walk')
9-
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
10-
parser.add_argument('-d','--depth', type = int, default = 1)
8+
parser.add_argument('-p', '--path', default='.', help='path to walk')
9+
parser.add_argument(
10+
'-f',
11+
'--fileinclude',
12+
action='store_true',
13+
help='if has, list files and dirs, else only dirs')
14+
parser.add_argument('-d', '--depth', type=int, default=1)
1115
#获取参数
1216
args = parser.parse_args()
1317
FILE = args.fileinclude
1418
PATH = args.path
1519
DEPTH = args.depth
1620

17-
18-
idxs = tree(PATH,DEPTH,FILE)
21+
idxs = tree(PATH, DEPTH, FILE)
1922
s = README.format(index='\n'.join(idxs))
20-
with open('README.md','w') as f:
23+
with open('README.md', 'w') as f:
2124
f.write(s)

utils/genZipFile.py

+30-15
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,62 @@
77
import argparse
88

99
parser = argparse.ArgumentParser()
10-
parser.add_argument('-r','--rewrite',help='rewrite zip file',action='store_true')
10+
parser.add_argument(
11+
'-r', '--rewrite', help='rewrite zip file', action='store_true')
1112
args = parser.parse_args()
1213
REWRITE = args.rewrite
1314

15+
1416
def checkZip(name):
1517
'''check if this file should be added to the zip'''
16-
li = [name.startswith('.') ,name.endswith('.zip'),name.lower()=='readme.md']
18+
li = [
19+
name.startswith('.'),
20+
name.endswith('.zip'),
21+
name.lower() == 'readme.md'
22+
]
1723
return not any(li)
1824

19-
def isIgnore(li,files):
20-
return 'index.html' in files or any((i[0]=='.' and i!='.') or i.startswith('__') or i in IGNORE for i in li)
21-
def genZipFile(tar = WALKDIR,rewrite=False):
25+
26+
def isIgnore(li, files):
27+
return 'index.html' in files or any(
28+
(i[0] == '.' and i != '.') or i.startswith('__') or i in IGNORE
29+
for i in li)
30+
31+
32+
def genZipFile(tar=WALKDIR, rewrite=False):
2233
os.chdir(tar)
2334
n = len(tar)
2435
gen = os.walk(tar)
2536
pwd = os.path.abspath('.')
2637
for path, dirs, files in gen:
2738
li = path.strip(os.sep).split(os.sep)
28-
if isIgnore(li,files):continue
39+
if isIgnore(li, files): continue
2940
ziplst = []
3041
for i in files:
3142
if i.endswith('个文件.zip'):
3243
if rewrite:
33-
os.remove(os.path.join(path,i))
34-
else:break
44+
os.remove(os.path.join(path, i))
45+
else:
46+
break
3547
elif checkZip(i):
36-
ziplst .append(i)
48+
ziplst.append(i)
3749
else:
38-
if len(ziplst)<3:continue
50+
if len(ziplst) < 3: continue
3951
ziplst.sort()
4052
tmp = os.path.abspath(path) \
4153
.replace(pwd,'')\
4254
.replace(os.sep,'-')
43-
name = '{tmp}目录下的{length}个文件.zip'.format(tmp=tmp,length =len(ziplst))
44-
zipName = os.path.join(path,name)
55+
name = '{tmp}目录下的{length}个文件.zip'.format(
56+
tmp=tmp, length=len(ziplst))
57+
zipName = os.path.join(path, name)
4558
try:
46-
with ZipFile(zipName,'w') as z:
59+
with ZipFile(zipName, 'w') as z:
4760
os.chdir(path)
48-
for i in ziplst: z.write(i)
61+
for i in ziplst:
62+
z.write(i)
4963
except Exception as e:
50-
print(e,path)
64+
print(e, path)
65+
5166

5267
if __name__ == '__main__':
5368
genZipFile(rewrite=REWRITE)

utils/getSize.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
# coding: utf-8
22
import os
33
import sys
4+
5+
46
def formatSize(size):
57
s = 'BKMGTP'
68
ct = 0
7-
while size>=(1<<ct):
8-
ct+=10
9-
if ct>=10: ct-=10
10-
return '{sz:.2f}{a}'.format(sz=size/(1<<ct),a=s[ct//10])
9+
while size >= (1 << ct):
10+
ct += 10
11+
if ct >= 10: ct -= 10
12+
return '{sz:.2f}{a}'.format(sz=size / (1 << ct), a=s[ct // 10])
1113

1214

1315
def getSize(path='.'):
1416
if os.path.isdir(path):
1517
gen = os.walk(path)
16-
li = []
18+
li = []
1719
for root, dirs, files in gen:
1820
for f in files:
19-
sz = os.path.getsize(os.path.join(root ,f))
21+
sz = os.path.getsize(os.path.join(root, f))
2022
li.append(sz)
2123
#li.insert(('.',sum(i[1] for i in li)),0)
2224
#size = [f'{i[0]}: {formatSize(i[1])}' for i in li]
2325
return formatSize(sum(li))
2426
else:
2527
return formatSize(os.path.getsize(path))
2628

29+
2730
if __name__ == "__main__":
2831
items = sys.argv[1:]
2932
for i in items:
30-
print('{i}: {sz}'.format(i=i,sz =getSize(i)))
33+
print('{i}: {sz}'.format(i=i, sz=getSize(i)))

utils/md_tree_links.py

+23-14
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,49 @@
66
#命令行输入参数处理
77
parser = ArgumentParser()
88

9-
parser.add_argument('-p','--path',default='.',help='path to walk')
10-
parser.add_argument('-f','--fileinclude',action='store_true',help='if has, list files and dirs, else only dirs')
11-
parser.add_argument('-d','--depth', type = int, default = 2)
9+
parser.add_argument('-p', '--path', default='.', help='path to walk')
10+
parser.add_argument(
11+
'-f',
12+
'--fileinclude',
13+
action='store_true',
14+
help='if has, list files and dirs, else only dirs')
15+
parser.add_argument('-d', '--depth', type=int, default=2)
1216
#获取参数
1317
args = parser.parse_args()
1418
FILE = args.fileinclude
1519
PATH = args.path
1620
DEPTH = args.depth
1721

22+
1823
def mklink(path):
19-
return '* [{name}]({path})'.format(name=os.path.basename(path),path=path)
24+
return '* [{name}]({path})'.format(name=os.path.basename(path), path=path)
25+
26+
2027
def clean(paths):
2128
ret = []
2229
for path in paths:
2330
name = os.path.basename(path)
24-
if not ( name.startswith('.') or name.startswith('__')):
31+
if not (name.startswith('.') or name.startswith('__')):
2532
ret.append(path)
2633
return ret
2734

28-
def tree(path='.',depth=2,showfile=False):
35+
36+
def tree(path='.', depth=2, showfile=False):
2937
while not os.path.isdir(path):
3038
print('[error]: please input a directory, not file path')
3139
path = input()
3240
li = os.listdir(path)
33-
items = [os.path.join(path,i) for i in li if not i.startswith('.')]
41+
items = [os.path.join(path, i) for i in li if not i.startswith('.')]
3442
items = clean(items)
3543
items = pinyinSort(items)
3644
if not showfile: items = [i for i in items if os.path.isdir(i)]
37-
if depth==1:
38-
return [mklink(path)] + [' '*4 + mklink(i) for i in items]
45+
if depth == 1:
46+
return [mklink(path)] + [' ' * 4 + mklink(i) for i in items]
3947
else:
40-
uls = [tree(i,depth-1,showfile) for i in items]
41-
ret = [' '*4 + li for ul in uls for li in ul]
42-
return [mklink(path)] + ret
48+
uls = [tree(i, depth - 1, showfile) for i in items]
49+
ret = [' ' * 4 + li for ul in uls for li in ul]
50+
return [mklink(path)] + ret
51+
4352

44-
if __name__ =='__main__':
45-
print('\n'.join(tree(PATH,DEPTH,FILE)))
53+
if __name__ == '__main__':
54+
print('\n'.join(tree(PATH, DEPTH, FILE)))

utils/mywalk.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import os
22

3-
def mywalk(dire,valid=lambda x:True):
3+
4+
def mywalk(dire, valid=lambda x: True):
45
if not os.path.isdir(dire):
56
raise Exception('[Error]: directory excepted')
67
dirs = []
78
files = []
89
for i in os.listdir(dire):
9-
i = os.path.join(dire,i)
10+
i = os.path.join(dire, i)
1011
if valid(i):
1112
if os.path.isdir(i):
1213
dirs.append(i)
1314
else:
1415
files.append(i)
15-
yield dire,dirs,files
16+
yield dire, dirs, files
1617
for d in dirs:
17-
yield from mywalk(os.path.join(dire,d),valid)
18+
yield from mywalk(os.path.join(dire, d), valid)

0 commit comments

Comments
 (0)