覆盖文件的权限 [英] Permission to overwrite files

查看:204
本文介绍了覆盖文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python程序,然后使用cx_freeze进行编译,该程序通过下载zip文件然后覆盖文件来进行自我更新。事情是,每当我执行它时,就会发生这种情况:

I have a python program which I then compile with cx_freeze that updates itself by downloading a zip file and then overwriting files. Thing is, whenever I execute it, this happens:

Traceback (most recent call last):
  File ".\updater.py", line 69, in empezar_actualizacion
    self.bajar_archivos()
  File ".\updater.py", line 75, in bajar_archivos
    self.extraer_archivos()
  File ".\updater.py", line 80, in extraer_archivos
    self.descarga.descomprimir(self.archivos)
  File "utils.py", line 167, in descomprimir
    raise(e)
IOError: [Errno 13] Permission denied: '_ctypes.pyd'

这是提取文件的代码:

class DescargaThread(threading.Thread):

    def __init__(self):
        self.url = config['servidor_de_actualizacion']

    def descargar_actualizacion(self):
        version = obtener_version()
        if not version:
            return 'Problemas de conexión, inténtelo después.'
        try:
            nueva_version = urllib.urlopen(self.url).read()
            return nueva_version
        except Exception as e:
            raise(e)

    def descomprimir(self, archivo):
        try:
            zip_file = zipfile.ZipFile(StringIO(archivo))
            for f in zip_file.namelist():
                self.file_unzipped = zip_file.extract(f)
            return True
        except Exception as e:
            raise(e)

我应该怎么做才能使文件覆盖自己?要求更高的权限?

What should I do to get the files to overwrite themselves? Ask for higher permissions?

推荐答案

当我使用Python部署Windows应用程序时,我使用 cx_freeze ,然后将其与打包在一起创新设置。然后,用户可以轻松下载并安装该应用程序。

When I deploy Windows application done in Python, I use cx_freeze and then pack it with Inno Setup. The user then downloads and installs the application painlessly.

该应用程序在启动时会检查Web服务器是否有更新。找到新版本后,它将询问用户是否要更新。如果是这样,应用程序将下载新的安装程序。您可以显示一些进度条,以便为用户提供良好的反馈。

The application checks the web server for updates when started. When the new version is found, it asks the user if he wants to update. If so, application downloads the new installer. You can show some progress bar to give user nice feedback.

完成后,它会根据存储库中可用的MD5或SHA1哈希检查下载的安装程序,然后启动安装程序并关闭

When finished, it checks the downloaded installer against MD5 or SHA1 hash available from the repository, starts the installer and closes the application in a way similar to this:

data = open(installer_path, "rb").read()
sha = hashlib.sha1(data).hexdigest()
if sha != shaWeb:
    blocking_message_box("Installer is corrupted.")
else:
    blocking_message_box("Installer is correct, will be installed now.")
    subprocess.Popen('"' + installer_path + '"', shell=True)
    this_application.Close()

用户现在完成安装。因为它以前已经安装过,所以我认为Inno安装程序将显示与以前使用的目录相同的目录,因此工作类似于 Next Next 完成。您可以以某种方式设置安装程序,以便保留用户设置等。您可以在静默模式下运行安装程序,但是当应用程序在后台执行某些操作时,很多用户都讨厌。

User now goes through the installation. Because it was already installed before, I think the Inno Setup will show up the same directory what was used before, so the effort is like Next, Next, Finish. You can setup your installer the way so it preserves user settings etc. You could probably run the installer in a silent mode, but a lot of users hate when application does something behind their back.

您还可以为已经安装了应用程序的用户创建类似更新的安装程序,跳过DLL和其他共享文件,仅更新 * .exe library.zip 。因为我的应用程序通常只有一个,所以无论如何我都会使用以下方式将 library.zip 嵌入可执行文件中:

You can also create an update-like installer for users who already have the application installed, skipping DLLs and other shared files, updating just the *.exe and library.zip. Because my applications usually have just one, I embed the library.zip in executable anyway, using:

options = {"build_exe": {"build_exe": "../Bin",
                          "create_shared_zip": False,
                         }}

这篇关于覆盖文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆