为什么Python可以通过Mac OS X上的Shell脚本正确解动zip文件?
设想:
Mac OS X Catalina 10.15
Python 3.10
我从几天开始就从事此任务。我正在使用Python开发Mac OS的软件。我使用py2app在mysoftware中转换我的python软件。
当时我的软件在检测新版本时需要自动自动化。
因此,我的想法是自动下载新的应用程序“ mysoftware.app”,删除旧的应用程序夹“/applications/mysoftware.app”,然后在文件夹中复制新的应用程序“/applications”。
我尝试了所有!!!
我使用了:
- 包装制作PKG
- DMG以将图像安装并提取到 /应用程序
- zip文件,然后将
所有这些技术手动运行良好,但是当我通过Python脚本自动化它时,它会发生错误。我经常会出现错误“您无法打开应用程序“ mysoftware”,因为它可能损坏或不完整。”当我双击我的应用程序时。
因此,我制作了一个bash脚本:
- 下载一个zip文件,其中包含新的“ mysoftware.app”
- unzip unzip it
- 删除旧的“/applications/mysoftware.app”
- cp -r new to to“ to“/applications”
shell shell Script autOupload。 当我从终端执行此外壳脚本时,它
#!/bin/bash
echo "------------- STARTING AutoUpdate.sh -----------------"
# If MySoftware.app doesn't exist, we unzip MySoftware_MAC.zip
if [[ ! -d "MySoftware.app" ]];then
echo "The directory MySoftware.app doesn't exist"
if [[ -f "MySoftware_MAC.zip" ]];then
unzip MySoftware_MAC.zip
echo "The file MySoftware_MAC.zip has been unzipped"
else
curl -sSL https://www.MySoftware.co/dist/MySoftware_MAC.zip --output MySoftware_MAC.zip
unzip MySoftware_MAC.zip
echo "The file MySoftware_MAC.zip has been unzipped"
fi
fi
rm -rf /Applications/MySoftware.app
echo "The folder /Applications/MySoftware.app has been removed"
#curl -sSL https://www.MySoftware.co/dist/MySoftware_MAC.zip --output MySoftware_MAC.zip
#echo "The file MySoftware_MAC.zip has been downloaded"
#unzip MySoftware_MAC.zip
cp -R MySoftware.app /Applications
echo "The folder MySoftware.app has been copied pasted to the folder /Applications"
osascript -e 'quit app "MySoftware"'
echo "The application MySoftware has been Quit"
open /Applications/MySoftware.app/Contents/MacOS/MySoftware
echo "The new application /Applications/MySoftware has been open"
的工作正常。我什至可以运行新的mysoftware.app
,但是当我从python脚本运行时,它会发生错误。
python脚本:,
down_url = f"http://www.MySoftware.co/dist/MySoftware_MAC.zip"
urllib.request.urlretrieve(down_url, MySoftware_MAC.zip)
down_url = f"http://www.MySoftware.co/dist/AutoUpdate.sh"
urllib.request.urlretrieve(down_url, 'AutoUpdate.sh')
os.system(f"chmod 755 'AutoUpdate.sh'")
command_run_autopupdate_shell_sript = f"""/usr/bin/osascript -e 'do shell script "/bin/bash 'AutoUpdate.sh' >> {os.environ['HOME']}/log_AutoUpdate.log" with prompt "Software need to install some programs." with administrator privileges'"""
proc = subprocess.Popen(command_run_autopupdate_shell_sript, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
(output, err) = proc.communicate()
logger.info(output.decode("utf8"))
logger.info(err.decode("utf8"))
returncode_command_install_Software = proc.wait()
logger.info(f"returncode_command_install_software : {returncode_command_install_Software}")
所以我试图将其执行为“ root”,但仍然存在同一问题。脚本很差“ mysoftware.app”。最糟糕的是,它没有显示任何错误消息。代码返回为0。
returncode_command_install_software : 0
如您在下面的屏幕截图中看到的,我将获得mysoftware.app带有错误的图标。当我双击它时,我会收到此弹出错误消息:
“您无法打开应用程序“ mysoftware”,因为它可能会损坏或不完整。”
为了模拟此自动启动,我将其与Py2App编译后执行Python脚本。
你们有什么想法吗?
ENVRIONMENT:
Mac OS X Catalina 10.15
Python 3.10
I worked since days on this task. I am developping a software for Mac OS with Python. I use Py2App to convert my python software in MySoftware.app
My software will need to autoupdate itself when it detect a new version.
So my idea was to auto download the new app "MySoftware.app", remove the old app folder "/Applications/MySoftware.app", and then copy paste the new one in the folder "/applications".
I tried it all!!!!
I used:
- packages to make a pkg
- dmg to mount image and extract to /Applications
- zip file and unzip to /Applications
All these technics run fine by hand but it bugs when I automate it through a python script. I constantly get the error "You can't open the application "MySoftware" because it may be damaged or incomplete." when I double click on my app.
So I made a bash script which :
- download a zip file which contains the new "MySoftware.app"
- unzip it
- remove old "/Applications/MySoftware.app"
- cp -R new one to "/Applications"
Shell Script AutoUpload.sh
#!/bin/bash
echo "------------- STARTING AutoUpdate.sh -----------------"
# If MySoftware.app doesn't exist, we unzip MySoftware_MAC.zip
if [[ ! -d "MySoftware.app" ]];then
echo "The directory MySoftware.app doesn't exist"
if [[ -f "MySoftware_MAC.zip" ]];then
unzip MySoftware_MAC.zip
echo "The file MySoftware_MAC.zip has been unzipped"
else
curl -sSL https://www.MySoftware.co/dist/MySoftware_MAC.zip --output MySoftware_MAC.zip
unzip MySoftware_MAC.zip
echo "The file MySoftware_MAC.zip has been unzipped"
fi
fi
rm -rf /Applications/MySoftware.app
echo "The folder /Applications/MySoftware.app has been removed"
#curl -sSL https://www.MySoftware.co/dist/MySoftware_MAC.zip --output MySoftware_MAC.zip
#echo "The file MySoftware_MAC.zip has been downloaded"
#unzip MySoftware_MAC.zip
cp -R MySoftware.app /Applications
echo "The folder MySoftware.app has been copied pasted to the folder /Applications"
osascript -e 'quit app "MySoftware"'
echo "The application MySoftware has been Quit"
open /Applications/MySoftware.app/Contents/MacOS/MySoftware
echo "The new application /Applications/MySoftware has been open"
It works perfectly fine when I execute this shell script from terminal. I can even run the new MySoftware.app
But it bugs when I run it from my python script.
Python Script:
down_url = f"http://www.MySoftware.co/dist/MySoftware_MAC.zip"
urllib.request.urlretrieve(down_url, MySoftware_MAC.zip)
down_url = f"http://www.MySoftware.co/dist/AutoUpdate.sh"
urllib.request.urlretrieve(down_url, 'AutoUpdate.sh')
os.system(f"chmod 755 'AutoUpdate.sh'")
command_run_autopupdate_shell_sript = f"""/usr/bin/osascript -e 'do shell script "/bin/bash 'AutoUpdate.sh' >> {os.environ['HOME']}/log_AutoUpdate.log" with prompt "Software need to install some programs." with administrator privileges'"""
proc = subprocess.Popen(command_run_autopupdate_shell_sript, stdout=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
(output, err) = proc.communicate()
logger.info(output.decode("utf8"))
logger.info(err.decode("utf8"))
returncode_command_install_Software = proc.wait()
logger.info(f"returncode_command_install_software : {returncode_command_install_Software}")
So I tried to execute it as "root", but still the same issue. The script unzip "MySoftware.app" badly. And the worst of all, it doesn't show any error message. The code return is 0.
returncode_command_install_software : 0
As you can see in screenshot below, I get the MySoftware.app with a wrong icon. When I double click on it, I get this popup error message:
"You can't open the application "MySoftware" because it may be damaged or incomplete."
To simulate this autoupdate, I execute my python script after I compiled it with Py2App.
Do you guys have any idea w
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论