winmnt_version.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. '''Created Jun 12, 2023 deeejas'''
  2. import ftplib
  3. import os
  4. import platform
  5. print(platform.python_version())
  6. # FTP server details
  7. ftp_host = 'ftp.winmentor.ro'
  8. ftp_user = 'anonymous'
  9. ftp_password = None # 'password'
  10. # Mentor Phats
  11. mentor_file_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/versiune.txt'
  12. mentor_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/MENTOR.ZIP'
  13. efact_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/Tools_si_alte_EXE_de_module/Server_WMEfact/WMEFact_net10.zip'
  14. mentor_changelog_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_KIT/Modificari versiunea curenta.pdf'
  15. # Declaration Paths
  16. decl_file_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/versiune.txt'
  17. decl_zip_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/REMOTE/Declaratii_R.zip'
  18. decl_changelog_path = '/WinMentor/Versiunea_Curenta/DECLARATII_KIT/Modificari versiunea curenta.pdf'
  19. # Correction Paths
  20. corr_file_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/versiune.txt'
  21. corr_zip_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/Mentor.zip'
  22. corr_changelog_path = '/WinMentor/Versiunea_Curenta/WinMENTOR_EXE_corectii_versiunea_curenta/Modificari versiunea curenta.pdf'
  23. # Local file path to save the downloaded files info
  24. tmp = 'tmp.txt'
  25. tmp_decl = 'tmp2.txt'
  26. tmp_corr = 'tmp3.txt'
  27. local_ment_path = 'versiune.txt'
  28. local_decl_path = 'versiune2.txt'
  29. local_corr_path = 'versiune3.txt'
  30. # Connect to the FTP server
  31. ftp = ftplib.FTP(ftp_host)
  32. ftp.login(ftp_user, ftp_password)
  33. def chk_mentor_version():
  34. with open(local_ment_path, 'r') as cversion, open(tmp, 'wb') as ftp_version:
  35. ftp.retrbinary('RETR ' + mentor_file_path, ftp_version.write)
  36. lines = list(cversion.readlines())[0].strip()[-8:]
  37. with open(tmp, 'r') as ftp_version:
  38. slines = list(ftp_version.readlines())[0].strip()[-8:]
  39. print('your mentor version', lines)
  40. print('server mentor version', slines)
  41. download = input('do you want to download this version? ')
  42. if download == 'y':
  43. if not os.path.exists(slines):
  44. os.makedirs(slines)
  45. with open(f'{slines}/MENTOR.zip', 'wb') as mentor_zip:
  46. ftp.retrbinary('RETR ' + mentor_zip_path, mentor_zip.write)
  47. with open(f'{slines}/WMEFact_net10.zip', 'wb') as efact_zip:
  48. ftp.retrbinary('RETR ' + efact_zip_path, efact_zip.write)
  49. with open(f'{slines}/changelog.pdf', 'wb') as changelog:
  50. ftp.retrbinary('RETR ' + mentor_changelog_path, changelog.write)
  51. else:
  52. pass
  53. def chk_corr_version():
  54. with open(local_corr_path, 'r') as cversion, open(tmp_corr, 'wb') as ftp_version:
  55. try:
  56. ftp.retrbinary('RETR ' + corr_file_path, ftp_version.write)
  57. lines = list(cversion.readlines())[0].strip()[-8:]
  58. except ftplib.error_perm:
  59. lines = 'no correction versions'
  60. try:
  61. with open(tmp_corr, 'r') as ftp_version:
  62. slines = list(ftp_version.readlines())[0].strip()[-8:]
  63. print('your correction version', lines)
  64. print('server correction version', slines)
  65. download = input('do you want to download this version? ')
  66. if download == 'y':
  67. if not os.path.exists(slines):
  68. os.makedirs(slines)
  69. with open(f'{slines}/Mentor.zip', 'wb') as corr_zip:
  70. ftp.retrbinary('RETR ' + corr_zip_path, corr_zip.write)
  71. with open(f'{slines}/changelog.pdf', 'wb') as changelog:
  72. ftp.retrbinary('RETR ' + corr_changelog_path, changelog.write)
  73. else:
  74. pass
  75. except IndexError:
  76. print('no correction versions')
  77. def chk_decl_version():
  78. with open(local_decl_path, 'r') as cversion, open(tmp_decl, 'wb') as ftp_version:
  79. ftp.retrbinary('RETR ' + decl_file_path, ftp_version.write)
  80. lines = list(cversion.readlines())[0].strip()[-9:-1]
  81. with open(tmp_decl, 'r') as ftp_version:
  82. slines = list(ftp_version.readlines())[0].strip()[-9:-1]
  83. print('your decl version', lines)
  84. print('server decl version', slines)
  85. download = input('do you want to download this version? ')
  86. if download == 'y':
  87. if not os.path.exists(f'DECLARATII/{slines}'):
  88. os.makedirs(f'DECLARATII/{slines}')
  89. with open(f'DECLARATII/{slines}/declaratii_R.zip', 'wb') as decl_zip:
  90. ftp.retrbinary('RETR ' + decl_zip_path, decl_zip.write)
  91. with open(f'DECLARATII/{slines}/changelog.pdf', 'wb') as changelog:
  92. ftp.retrbinary('RETR ' + decl_changelog_path, changelog.write)
  93. else:
  94. pass
  95. def save_version():
  96. save_versions = input('log the new versions? ')
  97. if save_versions == 'y':
  98. # Download the file
  99. with open(local_ment_path, 'wb') as local_file, open(local_decl_path, 'wb') as local_file2, open(local_corr_path, 'wb') as local_file3:
  100. ftp.retrbinary('RETR ' + mentor_file_path, local_file.write)
  101. ftp.retrbinary('RETR ' + decl_file_path, local_file2.write)
  102. try:
  103. ftp.retrbinary('RETR ' + corr_file_path, local_file3.write)
  104. except ftplib.error_perm:
  105. pass
  106. print('saved winmentor versions')
  107. else:
  108. print('nothing saved')
  109. if __name__ == '__main__':
  110. chk_mentor_version()
  111. chk_decl_version()
  112. chk_corr_version()
  113. save_version()
  114. ftp.quit()