Архив за день: 2020-06-08

auto-py-to-exe — компилятор питоновских скриптов для windows

Проверено на Python 3 — работает

Установка:

>c:\users\user\AppData\Local\Programs\Python\Python36\python.exe -m pip install auto-py-to-exe
Collecting auto-py-to-exe
  Downloading auto_py_to_exe-2.7.4-py2.py3-none-any.whl (74 kB)
     |████████████████████████████████| 74 kB 84 kB/s
....
Successfully installed Eel-0.11.0 altgraph-0.17 auto-py-to-exe-2.7.4 bottle-0.12
.18 bottle-websocket-0.2.9 cffi-1.14.0 future-0.18.2 gevent-20.6.0 gevent-websoc
ket-0.10.1 greenlet-0.4.16 pefile-2019.4.18 pycparser-2.20 pyinstaller-3.6 pywin
32-ctypes-0.2.0 whichcraft-0.6.1 zope.event-4.4 zope.interface-5.1.0

После успешной установки в папке Python36\Scripts\ появится auto-py-to-exe.exe, запускаем его

auto-py-to-exe
auto-py-to-exe

Выбираем скрипт, выставляем нужные настройки и жмём снизу «CONVERT .PY TO .EXE«. Появляется папка output с откомпилированным скриптом program.exe

Python скрипт для сбора информации по файлам в папке

# -*- coding: utf-8 -*-

'''
на входе папка или файл, на выходе CSV: имя файла;сумма мд5;папка полностью;имя компа
'''

import os
import hashlib
import platform
import time
import sys

class MyItem:
  def __init__(self, f):
    self.hostname = hostname
    self.md5sum = md5(f)
    self.size = os.path.getsize(f)
    self.created = "%s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getctime(f)))
    self.modified = "%s" % time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(os.path.getmtime(f)))
    self.ext = os.path.splitext(f)[1]
    self.full_dir, self.file_name = os.path.split(os.path.abspath(f))

def md5(fname):  # https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
    hash_md5 = hashlib.md5()
    with open(fname, "rb") as f:
        for chunk in iter(lambda: f.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()

hostname = platform.node()

result_header = "file_name;md5sum;size;created;modified;ext;full_path;hostname\n"
result_file = open('./result.csv','w')
result_file.write(result_header)

targets = []

if len(sys.argv) > 1:
  targets = sys.argv[1::]
else:
  targets.append(".")

for t in targets:
  if os.path.exists(t):
    if os.path.isdir(t):
      for current_dir, dirs, files in os.walk(t):
        for f in files:
          try:
            i = os.path.join(current_dir, f)
            print(i)
            item = MyItem(i)
            result_file.write('%s;%s;%s;%s;%s;%s;%s;%s\n'%(item.file_name, item.md5sum, item.size, item.created, item.modified, item.ext, item.full_dir, item.hostname))
          except:
            print('Error!')
    if os.path.isfile(t):
      try:
        i = t
        print(i)
        item = MyItem(i)
        result_file.write('%s;%s;%s;%s;%s;%s;%s;%s\n'%(item.file_name, item.md5sum, item.size, item.created, item.modified, item.ext, item.full_dir, item.hostname))
      except:
        print('Error!')

result_file.close()