Skip to content

Commit

Permalink
add datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
wxnacy committed Jun 6, 2019
1 parent 643151d commit cdcb81e
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 25 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.5
1.4.6
3 changes: 3 additions & 0 deletions bin/base/date
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo $(date '+%Y-%m-%d')
3 changes: 3 additions & 0 deletions bin/base/datetime
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')
3 changes: 3 additions & 0 deletions bin/base/size
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash


105 changes: 105 additions & 0 deletions bin/base/size.py
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)


22 changes: 22 additions & 0 deletions bin/base/split
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


22 changes: 22 additions & 0 deletions bin/base/split.awk
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


55 changes: 55 additions & 0 deletions bin/base/test_size.py
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()
3 changes: 3 additions & 0 deletions bin/base/time
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo $(date '+%H:%M:%S')
59 changes: 40 additions & 19 deletions bin/pyenv/install
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,35 @@ SYS=${OSS[0]}
VER=${OSS[1]}
PKG=${OSS[2]}

case $SYS in
debian|ubuntu|devuan|deepin)
sudo apt update -y
sudo apt -y install git gcc make patch zlib1g.dev libgdbm-dev libssl-dev libsqlite3-dev libbz2-dev libreadline-dev
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
;;
centos|fedora|rhel|amzn)
sudo yum update -y
sudo yum -y install git gcc readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
;;
Darwin)
brew update
brew install pyenv
;;
*)
echo '暂时不支持该系统'
;;
esac
pyver=$1

install_pyenv(){
path=`command -v pyenv`
if [ $path ];then
echo -e "pyenv is install on $path"
exit
fi

case $SYS in
debian|ubuntu|devuan|deepin)
sudo apt update -y
sudo apt -y install git gcc make patch zlib1g.dev libgdbm-dev libssl-dev libsqlite3-dev libbz2-dev libreadline-dev
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
;;
centos|fedora|rhel|amzn)
sudo yum update -y
sudo yum -y install git gcc readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
;;
Darwin)
brew update
brew install pyenv
;;
*)
echo '暂时不支持该系统'
;;
esac
}

# BP=~/.bash_profile
# if [ -f ~/.profile ];then
Expand All @@ -42,3 +52,14 @@ esac
# # nohup pyenv install 2.7.12 &
# # nohup pyenv install 3.6.0 &
# fi

if [ ! ${pyver} ]
then
install_pyenv
else
# url=https://www.python.org/ftp/python/${pyver}/Python-${pyver}.tar.xz
url=https://github.com/wxnacy/file/releases/download/python/Python-${pyver}.tar.xz
wget ${url} -P ~/.pyenv/cache/
pyenv install ${pyver}
# wget http://mirrors.sohu.com/python/${python_version}/Python-${python_version}.tar.xz \
fi
3 changes: 3 additions & 0 deletions conf/bash/bash_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ alias vgd="vagrant destroy -f"
# autossh
alias assh="autossh -M 0 "

# python
alias pipi="pip install -i https://pypi.tuna.tsinghua.edu.cn/simple"
alias pydb="python -m pdb"
3 changes: 0 additions & 3 deletions conf/bash/bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ export PATH=$PATH:/Users/wxnacy/PycharmProjects/study/goland/bin
export WS_HOME="${HOME}/.wshell"
export PATH=$PATH:${WS_HOME}/bin

# for image
export PATH=$PATH:/Users/wxnacy/Projects/image


function proxyoff(){
unset http_proxy
Expand Down
6 changes: 6 additions & 0 deletions conf/zsh/zprofile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ if [ -d "${HOME}/.nvm" ]; then
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
fi

# for python
# source /usr/local/opt/autoenv/activate.sh

# CFLAGS="-I$(brew --prefix openssl)/include" \
# LDFLAGS="-L$(brew --prefix openssl)/lib"
6 changes: 5 additions & 1 deletion conf/zsh/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export ZSH=${HOME}/.oh-my-zsh
# https://github.com/robbyrussell/oh-my-zsh/wiki/themes
# ZSH_THEME="fishy"
ZSH_THEME="bureau"
# ZSH_THEME="spaceship"
# source ${HOME}/.oh-my-zsh/themes/bureau.zsh-theme

# fpath=( "$HOME/.zfunctions" $fpath )
plugins=(git python sublime)
source $ZSH/oh-my-zsh.sh

Expand All @@ -19,3 +20,6 @@ source $ZSH/oh-my-zsh.sh
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
# autoload -U promptinit; promptinit

# prompt spaceship
6 changes: 6 additions & 0 deletions test/test/b.sh
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
2 changes: 1 addition & 1 deletion wshell-installer
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [[ ! $PATH =~ '.wshell/bin' ]];then
echo \' '>> ~/.bashrc'

echo -n -e "\t"echo \'
echo -n '. ${WS_HOME}/conf/system/bashrc'
echo -n '. ${WS_HOME}/conf/bash/bashrc'
echo \' '>> ~/.bashrc'

echo -e "\tsource ~/.bashrc"
Expand Down

0 comments on commit cdcb81e

Please sign in to comment.