[Terminal] python3 pip のアップデートとパッケージのアップデート
#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
###インストールするパッケージ
set listPackage to {"pip", "pypdf", "pypdf", "pdfautonup", "setuptools-scm", "stdeb", "PyPDF2", "PyPDF3", "pdfnup"} as list
try
do shell script "/usr/bin/xcode-select --install"
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/bin") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 700 $HOME/Library/Caches/pip") as text
do shell script strCmdText
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/Library/Caches/pip") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 777 $HOME/Library/Caches/pip") as text
do shell script strCmdText
end try
##
try
set strCmdText to ("/bin/mkdir -p $HOME/Library/Python/3.9/lib/python/site-packages") as text
do shell script strCmdText
set strCmdText to ("/bin/chmod 755 $HOME/Library/Python/3.9/lib/python/site-packages") as text
do shell script strCmdText
end try
## python3のパスチェック
try
set strCmdText to ("/usr/bin/which python3") as text
set strResponse to (do shell script strCmdText) as text
on error
return "python3が見つかりませんでした終了します"
end try
########################
#install
repeat with itemPackage in listPackage
set strPackageName to itemPackage as text
tell application "Terminal"
set strCmdText to ("\"" & strResponse & "\" -m pip install --user \"" & strPackageName & "\"") as text
do script strCmdText
activate
end tell
repeat 5 times
tell application "Terminal"
set numCntWindow to (count of every window) as integer
if numCntWindow = 1 then
log "Windowがありません"
exit repeat
end if
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is false then
log "処理していないので閉じる"
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
exit repeat
else
log "busyなので1秒まつ"
delay 1
end if
end repeat
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 1 then
log "Windowがありません"
else
###
tell application "Terminal"
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is true then
tell application "System Events"
tell application "Terminal" to activate
keystroke "c" using {control down}
end tell
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
end if
end if
end repeat
########################
#upgrade
repeat with itemPackage in listPackage
set strPackageName to itemPackage as text
tell application "Terminal"
set strCmdText to ("\"" & strResponse & "\" -m pip install --upgrade --user \"" & strPackageName & "\"") as text
do script strCmdText
activate
end tell
repeat 5 times
tell application "Terminal"
set numCntWindow to (count of every window) as integer
if numCntWindow = 1 then
log "Windowがありません"
exit repeat
end if
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is false then
log "処理していないので閉じる"
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
exit repeat
else
log "busyなので1秒まつ"
delay 1
end if
end repeat
tell application "Terminal"
set numCntWindow to (count of every window) as integer
end tell
if numCntWindow = 1 then
log "Windowがありません"
else
###
tell application "Terminal"
tell front window
set numWindowID to id
tell front tab
set boolBusy to busy as boolean
end tell
end tell
end tell
if boolBusy is true then
tell application "System Events"
tell application "Terminal" to activate
keystroke "c" using {control down}
end tell
tell application "Terminal"
do script "\n\n" in window id numWindowID
do script "exit" in window id numWindowID
delay 1
close front window saving no
end tell
end if
end if
end repeat
display notification "処理終了" with title "処理が終了" subtitle "処理が終了しました" sound name "Sonumi"
return
| 固定リンク
「Python」カテゴリの記事
- [selenium]chromedriverを使って指定URLのタイトルを取得する(2024.11.24)
- PDFで使用されているフォントをページ毎に調べてテキスト出力する(2024.08.30)
- [python]画像データを非圧縮でPDF化する(2024.06.28)
- [cv2]画像をグレースケールに変換します(2024.06.12)
- [cv2]画像を白黒にする(128階調目で白黒)(2024.06.12)
「Terminal」カテゴリの記事
- [Terminal]新規Windowでコマンドを実行するまでの一連の流れ(2025.01.13)
- ターミナル終了(複数Window 複数tab時)(2024.12.30)
- ターミナル終了(単Window時)(2024.12.30)
- ターミナル 実行中のプロセスの終了とウィンドウを閉じる(2024.11.24)
- [Terminal]スクリプト実行後終了したらTerminalも終了する(2024.11.14)