-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
278 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.4.5 | ||
1.4.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo $(date '+%Y-%m-%d') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo $(date '+%Y-%m-%d %H:%M:%S') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
import os | ||
|
||
|
||
def get_size(path): | ||
'''获取文件的大小''' | ||
def _size(p, s: int): | ||
if os.path.isfile(p): | ||
s += os.path.getsize(p) | ||
# print(s, os.path.getsize(p), p) | ||
else: | ||
files = os.listdir(p) | ||
for f in files: | ||
fp = '{}/{}'.format(p, f) | ||
s = _size(fp, s) | ||
return s | ||
res = _size(path, 0) | ||
# print(res) | ||
return res | ||
|
||
def get_size1(path): | ||
'''获取文件的大小''' | ||
if os.path.isfile(path): | ||
return os.path.getsize(path) | ||
|
||
size = 0 | ||
for root, dirs, filenames in os.walk(path): | ||
for filename in filenames: | ||
filepath = '{}/{}'.format(root, filename) | ||
size += os.path.getsize(filepath) | ||
return size | ||
|
||
def format_size(size: int): | ||
'''格式化大小''' | ||
|
||
unit = { | ||
0: 'B', | ||
1: 'K', | ||
2: 'M', | ||
3: 'T', | ||
4: 'P', | ||
} | ||
|
||
for i in range(1, 6): | ||
max_size = 1024 ** i | ||
if size < max_size: | ||
j = i - 1 | ||
if j < 1: | ||
res = size | ||
else: | ||
res = size / 1028 * j | ||
return '{:0.1f}{}'.format( res, unit[j]) | ||
|
||
class File(): | ||
def __init__(self, path, *args, **kwargs): | ||
self.path = path | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
args = sys.argv[1:] | ||
path = '.' | ||
is_fmt = False | ||
for a in args: | ||
if not a.startswith('-') and a: | ||
path = a | ||
if a == '-h': | ||
is_fmt = True | ||
|
||
# if len(args) >=1: | ||
# path = args[0] | ||
|
||
# print(path) | ||
|
||
lists = [] | ||
|
||
total_size = 0 | ||
if os.path.isfile(path): | ||
print(os.path.getsize(path)) | ||
sys.exit(0) | ||
files = os.listdir(path) | ||
for f in files: | ||
filepath = '{}/{}'.format(path, f) | ||
size = get_size(filepath) | ||
total_size += size | ||
fmt_size = format_size(size) if is_fmt else size | ||
line = '{}\t\t{}'.format(fmt_size, f) | ||
print(line) | ||
lists.append(dict(size= size, name = f)) | ||
fmt_total = format_size(total_size) if is_fmt else total_size | ||
print('Total:', fmt_total) | ||
print('开始排序') | ||
|
||
lists.sort(key = lambda o: o['size'], reverse=True) | ||
for l in lists[0:10]: | ||
size = l['size'] | ||
f = l['name'] | ||
fmt_size = format_size(size) if is_fmt else size | ||
line = '{}\t\t{}'.format(fmt_size, f) | ||
print(line) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo $@ | ||
echo 'split' | ||
|
||
file=$1 | ||
sep=$2 | ||
|
||
if [ $sep == "-d" ] | ||
then | ||
echo 's' | ||
d=`date '+%Y-%m-%d'` | ||
echo $d | ||
# echo $(awk '/$d 00/ {print $0}' $file) | ||
cmd="awk '" | ||
cmd=${cmd}"/$d/ {print \$0}" | ||
cmd=${cmd}"' $file" | ||
echo $cmd | ||
`$cmd` | ||
fi | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env awk -f | ||
|
||
echo $@ | ||
echo 'split' | ||
|
||
file=$1 | ||
sep=$2 | ||
|
||
if [ $sep == "-d" ] | ||
then | ||
echo 's' | ||
d=`date '+%Y-%m-%d'` | ||
echo $d | ||
# echo $(awk '/$d 00/ {print $0}' $file) | ||
cmd="awk '" | ||
cmd=${cmd}"/$d/ {print \$0}" | ||
cmd=${cmd}"' $file" | ||
echo $cmd | ||
`$cmd` | ||
fi | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
import unittest | ||
import timeit | ||
from size import get_size | ||
from size import get_size1 | ||
from size import format_size | ||
|
||
class TestMain(unittest.TestCase): | ||
|
||
def setUp(self): | ||
'''before each test function''' | ||
pass | ||
|
||
def tearDown(self): | ||
'''after each test function''' | ||
pass | ||
|
||
def do(self, func): | ||
'''todo''' | ||
self.assertEqual(1, 1) | ||
pass | ||
|
||
def test_func(self): | ||
# self.do() | ||
path = '/Users/wxnacy/Documents' | ||
self.assertEqual(get_size(path), get_size1(path)) | ||
|
||
self.assertEqual | ||
|
||
def test_format_size(self): | ||
self.assertEqual(format_size(234), '234.0B') | ||
self.assertEqual(format_size(1234), '1.2K') | ||
|
||
def speed(count, func, *args): | ||
b = timeit.default_timer() | ||
for i in range(count): | ||
func(*args) | ||
print('{} run {} times used: {}s'.format( | ||
func.__name__.ljust(20), count, | ||
timeit.default_timer() - b | ||
)) | ||
|
||
|
||
if __name__ == "__main__": | ||
count = 15 | ||
path = '/Users/wxnacy/Documents' | ||
speed(count, get_size, path) | ||
speed(count, get_size1, path) | ||
|
||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo $(date '+%H:%M:%S') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
# source a.sh | ||
. a.sh | ||
echo $name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters