Skip to content

Commit 263e232

Browse files
authored
Merge pull request #11 from jumploop/dev
Dev
2 parents f66f18d + c251534 commit 263e232

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

shell/lazy_find.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
# lazy find
3+
4+
# GNU All-Permissive License
5+
# Copying and distribution of this file, with or without modification,
6+
# are permitted in any medium without royalty provided the copyright
7+
# notice and this notice are preserved. This file is offered as-is,
8+
# without any warranty.
9+
10+
## help function
11+
12+
function helpu {
13+
echo " "
14+
echo "Fuzzy search for filename."
15+
echo "$0 [--match-case|--path] filename"
16+
echo " "
17+
exit
18+
}
19+
20+
## set variables
21+
22+
MATCH="-iname"
23+
SEARCH="."
24+
25+
## parse options
26+
27+
while [ True ]; do
28+
if [ "$1" = "--help" -o "$1" = "-h" ]; then
29+
helpu
30+
elif [ "$1" = "--match-case" -o "$1" = "-m" ]; then
31+
MATCH="-name"
32+
shift 1
33+
elif [ "$1" = "--path" -o "$1" = "-p" ]; then
34+
SEARCH="${2}"
35+
shift 2
36+
else
37+
break
38+
fi
39+
done
40+
41+
## sanitize input filenames
42+
## create array, retain spaces
43+
44+
ARG=("${@}")
45+
set -e
46+
47+
## catch obvious input error
48+
49+
if [ "X$ARG" = "X" ]; then
50+
helpu
51+
fi
52+
53+
## perform search
54+
55+
for query in ${ARG[*]}; do
56+
/usr/bin/find "${SEARCH}" "${MATCH}" "*${ARG}*"
57+
done

zip/pack_zipfile.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# @Time : 2022/2/26 16:55
4+
# @Author : 一叶知秋
5+
# @File : pack_zipfile.py
6+
# @Software: PyCharm
7+
from __future__ import print_function
8+
import os
9+
import sys
10+
import zipfile
11+
import logging
12+
13+
if sys.version_info[0] == 2:
14+
input = raw_input
15+
else:
16+
input = input
17+
formatter = '%(asctime)s %(levelname)s %(filename)s[%(lineno)d]: %(message)s'
18+
logging.basicConfig(level=logging.DEBUG, format=formatter,
19+
datefmt='%Y:%m:%d %H:%M:%S', encoding='utf-8')
20+
21+
22+
def make_zip_file(filename, sourcefolder):
23+
"""
24+
make zip file
25+
:param filename: zip file name
26+
:param sourceFolder: source file folder
27+
:return:
28+
"""
29+
with zipfile.ZipFile(filename, mode='w', compression=zipfile.ZIP_DEFLATED) as zip_file:
30+
for root, dirs, files in os.walk(sourcefolder):
31+
for file in files:
32+
fullpath = os.path.join(root, file)
33+
logging.info('filename is %s', fullpath)
34+
arcname = fullpath.replace(sourcefolder, '')
35+
logging.info('arcname is %s', arcname)
36+
zip_file.write(fullpath, arcname)
37+
38+
39+
def main():
40+
sourceFolder = input('请输入源文件路径目录:\n')
41+
filename = input('请输入压缩文件名字: \n')
42+
logging.info('source file dir: %s', sourceFolder)
43+
logging.info('zip file name: %s', filename)
44+
make_zip_file(filename, sourceFolder)
45+
46+
47+
if __name__ == '__main__':
48+
main()

0 commit comments

Comments
 (0)