docopt and docstring
docopt
overview
- This tool parses help statement in doc.
preference
- GitHub site
- Show Usage in Japanese
installation
G:\ > pip install docopt
usage
How to use
- docopt形式で、パッケージのdocに記述する。
- 以下のサイトで検証する
- Try docopt
docopt—language for description of command-line interfaces
- 検証例
sample statement
"""{fname} # sample code for docopt usage Usage: {fname} -h | --help {fname} --version {fname} --id=<id> --no=<no> Options: -h --help Show this screen. --version Show version. --id=<id> Set id for process --no=<no> Set no for process """
list
elements | description | note |
---|---|---|
<argument> | argument | <x>の場所に1を与えれば、{"<x>" : 1,}となる |
--option, -o | option | ハイフンで開始 |
(arguments) | required | 必須(デフォルトで必須) |
[arguments] | optioned | 指定なしでもOK |
-h | --help | -h もしくは --help | |
args... | 可変引数 | リストで引数が取得される |
sample code
#! /usr/bin/env python """{fname} # sample code for docopt usage Usage: {fname} -h | --help {fname} --version {fname} --id=<id> --no=<no> Options: -h --help Show this screen. --version Show version. --id=<id> Set id for process --no=<no> Set no for process """ __author__ = 'Memoru' __version__ = '0.0.1' __date__ = '06/08/18' import sys import os __doc__ = __doc__.format(fname=os.path.basename(__file__)) from docopt import docopt import logging.config # ----------------------------------------- # def _isNoneOrEmptyOrBlankString (_s): """# string check routine for None and Blank and Empty @param _s {string} for check @return {boolean} """ if _s: if not _s.strip(): return True else: return False return False def process(): """# main process """ logger = logging.getLogger(__name__) args = docopt(__doc__) logger.debug("\n"+str(args)) if args["--version"]: print(__version__) sys.exit() try: if _isNoneOrEmptyOrBlankString(args["--id"]) or _isNoneOrEmptyOrBlankString(args["--no"]): msg = 'args do not allow space or null.' raise ValueError(msg) else: logger.info(f'{args["--id"]}-{args["--no"]}') except Exception as ex: logger.exception(ex) sys.exit(1) if __name__ == '__main__': logging.config.fileConfig("logging.conf") process()
実行例
#============================================================ #DateTime : Saturday, June 9, 2018 12:31:22 PM #CmdLine : python G:\workplace\py\sandbox\docopt_sample\docopt_sample.py --id=1111 --no="123" #============================================================ [2018/06/09 12:31:23][DEBUG](docopt_sample.py:47) {'--help': False, '--id': '1111', '--no': '123', '--version': False} [2018/06/09 12:31:23][INFO](docopt_sample.py:57) 1111-123 終了コード: 0
#============================================================ #DateTime : Saturday, June 9, 2018 12:31:38 PM #CmdLine : python G:\workplace\py\sandbox\docopt_sample\docopt_sample.py --version #============================================================ [2018/06/09 12:31:38][DEBUG](docopt_sample.py:47) {'--help': False, '--id': None, '--no': None, '--version': True} 0.0.1 終了コード: 0
#============================================================ #DateTime : Saturday, June 9, 2018 12:31:51 PM #CmdLine : python G:\workplace\py\sandbox\docopt_sample\docopt_sample.py --help #============================================================ docopt_sample.py # sample code for docopt usage Usage: docopt_sample.py -h | --help docopt_sample.py --version docopt_sample.py --id=<id> --no=<no> Options: -h --help Show this screen. --version Show version. --id=<id> Set id for process --no=<no> Set no for process 終了コード: 0
supplementary
(sandbox) PS G:\workplace\py\sandbox\docopt_sample> python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import docopt_sample >>> help(docopt_sample) Help on module docopt_sample: NAME docopt_sample DESCRIPTION docopt_sample.py # sample code for docopt usage Usage: docopt_sample.py -h | --help docopt_sample.py --version docopt_sample.py --id=<id> --no=<no> Options: -h --help Show this screen. --version Show version. --id=<id> Set id for process --no=<no> Set no for process FUNCTIONS process() # main process VERSION 0.0.1 DATE 06/08/18 AUTHOR Memoru FILE g:\workplace\py\sandbox\docopt_sample\docopt_sample.py >>> help(docopt_sample._isNoneOrEmptyOrBlankString) Help on function _isNoneOrEmptyOrBlankString in module docopt_sample: _isNoneOrEmptyOrBlankString(_s) # string check routine for None and Blank and Empty @param _s {string} for check @return {boolean} >>> quit()
// --- end of wiki
gibo
.gitignore boilerplates
Overview
- gibo is a shell script to help easily access .gitignore boilerplates.
download
- gibo
installation
- GitHubサイトをclone
- pathを通す。
Environment
PS G:\Users\sakai> $env:path.split(";") | Out-String -Stream | sls gibo G:\Users\sakai\Downloads\gibo PS G:\Users\sakai> gibo --version gibo 1.0.6 by Simon Whitaker <sw@netcetera.org> https://github.com/simonwhitaker/gitignore-boilerplates
Usage
PS G:\Users\sakai> workon Pass a name to activate one of the following virtualenvs: ============================================================================== djfirst djsecond sandbox PS G:\Users\sakai> $p = "sandbox" PS G:\Users\sakai> cd $Env:WORKON_HOME/$p PS G:\env\py> .\Scripts\activate (sandbox) PS G:\env\py> cd $Env:PROJECT_HOME/$p (sandbox) PS G:\workplace\py\sandbox> gibo python vim > .gitignore (sandbox) PS G:\workplace\py\sandbox> sakura .\.gitignore
‐ 以下を追加し、UTF-8で保存する。(powershellで、redirectすると、UNICODE BOM付で生成されるため)
temp/ backup/ *.log *.log.*
// --- end of blog
python組み込み変数
組み込み変数
variable | content | note |
---|---|---|
__file__ | 実行script full path | |
__name__ | 実行script module |
sample
- logging_sample.py
#! /usr/bin/env python """sample code for __file__ """ import logging import logging.config import os import sys ### ----------------------------------------- ### def process(): logger = logging.getLogger(__name__) logger.debug("debug") logger.info(os.path.abspath(__file__)) logger.info(os.path.dirname(__file__)) logger.info(os.path.basename(__file__)) logger.info(os.path.split(sys.argv[0])[0]) logger.info(os.path.split(sys.argv[0])[-1]) if __name__ == '__main__': logging.config.fileConfig("logging.conf") process()
- log
#============================================================ #DateTime : Friday, June 8, 2018 6:31:42 AM #CmdLine : python G:\workplace\py\sandbox\logging_sample.py #============================================================ [2018/06/08 06:31:42][DEBUG](logging_sample.py:12) debug [2018/06/08 06:31:42][INFO](logging_sample.py:13) G:\workplace\py\sandbox\logging_sample.py [2018/06/08 06:31:42][INFO](logging_sample.py:14) G:\workplace\py\sandbox [2018/06/08 06:31:42][INFO](logging_sample.py:15) logging_sample.py [2018/06/08 06:31:42][INFO](logging_sample.py:16) G:\workplace\py\sandbox [2018/06/08 06:31:42][INFO](logging_sample.py:17) logging_sample.py 終了コード: 0
- logging_debug.conf
[loggers] keys=root,functions [handlers] keys=fileHandler,stderrHandler [formatters] keys=simpleFormatter [logger_root] level=DEBUG handlers=fileHandler,stderrHandler [logger_functions] level=INFO handlers=fileHandler,stderrHandler qualname=functions propagate=0 [handler_fileHandler] class=handlers.TimedRotatingFileHandler formatter=simpleFormatter args=('apps.log','D') [handler_stderrHandler] class=StreamHandler formatter=simpleFormatter args=(sys.stderr,) [formatter_simpleFormatter] format=[%(asctime)s][%(levelname)s](%(filename)s:%(lineno)s) %(message)s datefmt=%Y/%m/%d %H:%M:%S
reference
// --- end of blog
win key shortcuts on windows 10
Win key shortcuts
Windows and Virtual Desktop
shortcut | application or operations | note |
---|---|---|
win+↑ | Maximize Window | |
win+shift + ↑ | Maximize 縦 windows | |
win+↓ | Minimize Window | |
win+M | Minimize all windows | |
win+Tab | Task Viewer | |
win+ctrl+LEFT/RIGHT | Switch virtual desktop |
Windows OS Operation
shortcut | application or operations | note |
---|---|---|
win+I | Open Settings | |
win+L | Lock your PC or switch accounts | |
win+R | Open Run Dialog box | |
win+S | Open Search | |
win+x | Open Quick Link Menu | |
win+space | switch keyboard on language |
Task and Window Management
shortcut | application or operations | note |
---|---|---|
win | Start Menu | |
ctrl+Esc | Start Menu | |
win+E | Display Computer | |
win+D | Display and hide the desktop | |
win+T | Focus on Task bar | |
win+B | Focus on Button indicator | |
ctrl+shift+Tab | Display Task Manager | |
alt+Tab | Switch Task | |
alt+Esc | Switch Task |
Activate Task bar Application
shortcut | application or operations | note |
---|---|---|
win+1 | Edge | |
win+2 | Explorer | |
win+3 | ||
win+4 | Terminal | |
win+5 | Calendar | |
win+6 | Todo | |
win+7 | Logging | |
win+8 | Editor | |
win+9 | Writer (markdown) | |
win+0 | Chat | |
- - - | Focus |
// --- end of blog
($Env:path).split(";")
list up in environment variables with windows os
$Env:path.split(";")
ps > ($Env:path).split(";") C:\ProgramData\Anaconda3 C:\ProgramData\Anaconda3\Library\mingw-w64\bin C:\ProgramData\Anaconda3\Library\usr\bin C:\ProgramData\Anaconda3\Library\bin C:\ProgramData\Anaconda3\Scripts C:\Program Files (x86)\Python36-32\Scripts\ C:\Program Files (x86)\Python36-32\ C:\Program Files (x86)\Common Files\Oracle\Java\javapath C:\ProgramData\Oracle\Java\javapath C:\WINDOWS\system32 C:\WINDOWS C:\WINDOWS\System32\Wbem C:\WINDOWS\System32\WindowsPowerShell\v1.0\ C:\WINDOWS\system32\config\systemprofile\.dnx\bin C:\Program Files\Microsoft DNX\Dnvm\ C:\Program Files\Microsoft SQL Server\130\Tools\Binn\ G:\Users\usr_name\Desktop\tool G:\Users\usr_name\Desktop G:\Redis\ C:\Program Files\MongoDB\Server\3.2\bin G:\Python27 C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\ C:\Program Files\Microsoft SQL Server\120\Tools\Binn\ G:\xampp\php C:\Program Files\nodejs\ C:\Program Files (x86)\Graphviz2.38\ C:\Program Files (x86)\MeCab\bin C:\Program Files (x86)\WinMerge C:\Program Files (x86)\mosquitto C:\Program Files\Git\cmd C:\WINDOWS\System32\OpenSSH\ C:\Program Files (x86)\sakura G:\Users\usr_name\Downloads\vim80-kaoriya-win64-8.0.0596-20170502\vim80-kaoriya-win64 G:\Users\usr_name\AppData\Local\Microsoft\WindowsApps G:\Users\usr_name\AppData\Local\atom\bin
$Env:path.split(";") | out-string -stream | select-string py
PS > $Env:path.split(";") | out-string -stream | select-string py G:\Users\usr_name\AppData\Local\Programs\Python\Python36-32\Scripts\ G:\Users\usr_name\AppData\Local\Programs\Python\Python36-32\