×

欢迎光临,有什么想法就留言告诉我吧!

你的精彩评论可能会出现在这里哦! 留言抢沙发

python

一键删除项目中的__pycache__文件夹

穆琪 穆琪 发表于2023-10-27 浏览24 评论0

背景

在编码过程中,运行测试代码之后总会生成一些pyc文件在pycache目录下面,虽然修改.gitignore可以保证提交中不含有这些文件,但是要想获取一个干净的目录的话还是删掉为好。这里就编写了一个脚本,用来删除一个目录下所有的__pycache__目录,包括子目录下的。

代码

import os
import shutil
# 需要遍历的目录
root_dir = "F:\work\xxx"
# 遍历目录
for dirpath, dirnames, filenames in os.walk(root_dir):
    if "__pycache__" in dirnames:
        # 获取 __pycache__ 目录的全路径
        pycache_dir = os.path.join(dirpath, "__pycache__")
        # 删除目录
        shutil.rmtree(pycache_dir)
        print(f"Removed: {pycache_dir}")

杂项

vim配置备份

穆琪 穆琪 发表于2023-08-30 浏览469 评论0
" vundle config
set nocompatible              " required
filetype off                  " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'https://github.com/scrooloose/nerdtree'
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'https://github.com/bling/vim-airline'
" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" user config
" 通用配置
syntax on
set ic
set hlsearch
set encoding=utf-8
set fileencodings=utf-8,ucs-bom,GB2312,big5
set cursorline
set autoindent
set smartindent
set scrolloff=4
set showmatch
set nu
" python文件配置
let python_highlight_all=1
au Filetype python set tabstop=4
au Filetype python set softtabstop=4
au Filetype python set shiftwidth=4
au Filetype python set textwidth=79
au Filetype python set expandtab
au Filetype python set autoindent
au Filetype python set fileformat=unix
autocmd Filetype python set foldmethod=indent
autocmd Filetype python set foldlevel=99
" 分割窗口配置
set splitbelow
set splitright
" split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" 代码折叠
set foldmethod=indent
set foldlevel=99
nnoremap <space> za
" 文件树配置
nnoremap <F3> :NERDTreeToggle<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" 括号匹配颜色配置
let g:rbpt_colorpairs = [
                        \ ['brown',       'RoyalBlue3'],
                        \ ['Darkblue',    'SeaGreen3'],
                        \ ['darkgray',    'DarkOrchid3'],
                        \ ['darkgreen',   'firebrick3'],
                        \ ['darkcyan',    'RoyalBlue3'],
                        \ ['darkred',     'SeaGreen3'],
                        \ ['darkmagenta', 'DarkOrchid3'],
                        \ ['brown',       'firebrick3'],
                        \ ['gray',        'RoyalBlue3'],
                        \ ['darkmagenta', 'DarkOrchid3'],
                        \ ['Darkblue',    'firebrick3'],
                        \ ['darkgreen',   'RoyalBlue3'],
                        \ ['darkcyan',    'SeaGreen3'],
                        \ ['darkred',     'DarkOrchid3'],
                        \ ['red',         'firebrick3'],
                        \ ]
let g:rbpt_max = 16
let g:rbpt_loadcmd_toggle = 0
au VimEnter * RainbowParenthesesToggle
au Syntax * RainbowParenthesesLoadRound
au Syntax * RainbowParenthesesLoadSquare
au Syntax * RainbowParenthesesLoadBraces

操作系统

docker根据overlay2的目录名找到对应的容器

穆琪 穆琪 发表于2023-06-06 浏览93 评论0

背景

在工作中,有一段旧代码在容器中使用了临时文件库tmpfile,并设置为不自动删除,所以临时文件一直堆积在/tmp目录下。

而容器中的tmp目录是不会清理的,终于有一天,整个var目录满了。

查到overlay2目录下的某个目录占用比较大,就需要根据目录名找到对应的容器

操作语句

docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Id}}, {{.Name}}, {{.GraphDriver.Data.WorkDir}}' | grep '目录名'

数据库

redis查看占用内存大的key

穆琪 穆琪 发表于2023-05-15 浏览143 评论0

背景

在测试环境中,经常出现某些同事乱用redis存数据,导致redis内存不够用,所以有下面的命令来查redis的内存占用和占用大的key。

命令

查看redis占用内存信息

docker环境:

docker exec -i redis redis-cli -h 127.0.0.1 -p 6379 -a <password> -n 1 info Memory