Advertisement
JachyHm

runactualization.py

Apr 11th, 2017
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. import socket
  2. import time
  3. from prompter import yesno
  4. import os.path
  5. import os
  6. import zipfile
  7. import urllib.request
  8. import requests
  9. import queue
  10. import math
  11. from ruamel.std.zipfile import delete_from_zip_file
  12. from winreg import *
  13. queue.Queue()
  14. #cesta = Assets\CS_addon\Smejki\RailVehicles\Electric\460080\ActualizationAutoRun\
  15. class Download:
  16.         def download_file(self,url,basepath):
  17.                 procenta = 0
  18.                 procentastare = 0
  19.                 local_filename = os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip"))
  20.                 r = requests.get(url, stream=True)
  21.                 with open(local_filename, 'wb') as f:
  22.                         for chunk in r.iter_content(chunk_size=1024):
  23.                                 if chunk:
  24.                                         f.write(chunk)
  25.                                         if math.floor(procenta) != procentastare:
  26.                                                 procentastare = math.floor(procenta)
  27.                                                 print("Staženo cca. "+str(math.floor(procenta))+"%")
  28.                                         procenta = procenta + 0.00068990608114481
  29.                 return local_filename
  30. class Main:
  31.         def __init__(self):
  32.                 download = Download()
  33.                 basepath = os.getcwd()
  34.                 filepath = os.path.abspath(os.path.join(basepath, "Dialogs", "DriverInstructions" ,"AssignmentDialogListItem.ed"))
  35.                 try:
  36.                         staraverzef = open(filepath, "r")
  37.                         staraverze = staraverzef.read()
  38.                         staraverzef.close()
  39.                 except:
  40.                         print("Soubor stará verze nebyl nalezen!")
  41.                         input(os.getcwd())
  42.                         staraverze = 0
  43.                 if staraverze == "":
  44.                         staraverze = "0"
  45.                 with urllib.request.urlopen("http://jachyhm.cz/verze460.txt") as url:
  46.                         novaverze = int(url.read())
  47.                 if int(staraverze) < int(novaverze):
  48.                         try:
  49.                                 print("Aktualizace EMU460!")
  50.                                 print("Stahuji!")
  51.                                 download.download_file("http://jachyhm.cz/460autoaktualizace.rwp",basepath)
  52.                         except:
  53.                                 print("Chyba při stahování! Nelze navázat spojení se serverem!")
  54.                         else:
  55.                                 print("Úspěšně staženo, rozbaluji...")
  56.                                 delete_from_zip_file(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")), pattern=".*.exe")
  57.                                 with zipfile.ZipFile(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")),"r") as zip_ref:
  58.                                         zip_ref.extractall(os.path.abspath(basepath))
  59.                                 novaverzef = open(filepath, "w")
  60.                                 novaverzef.write(str(novaverze))
  61.                                 novaverzef.close()
  62.                                 os.remove(os.path.abspath(os.path.join(basepath, "aktualizace460TEMP.zip")))
  63. m=Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement