
def disk_info(path,conn):
    import wmi
    DRIVE_TYPES = {
      0 : "Unknown",
      1 : "No Root Directory",
      2 : "Removable Disk",
      3 : "Local Disk",
      4 : "Network Drive",
      5 : "Compact Disc",
      6 : "RAM Disk"
    }
    if path[1]==":":
        c = wmi.WMI ()
        for drive in c.Win32_LogicalDisk ():
            # prints all the drives details including name, type and size
            if drive.Caption.upper()==path[0:2].upper():
                # print(drive)
                # print (drive.Caption, drive.SystemName,drive.VolumeSerialNumber,drive.VolumeName, DRIVE_TYPES[drive.DriveType])
                cur = conn.cursor()
                cur.execute("select id from tdevices where volumename=%s and devicecaption=%s and systemname=%s and volumeserial=%s and type=%s",(drive.Caption, drive.SystemName,drive.VolumeSerialNumber,drive.VolumeName, DRIVE_TYPES[drive.DriveType]))
                f=cur.fetchone()
                if len(f)==0:
                    cur.execute("insert into tdevices (volumename, devicecaption, systemname, volumeserial, type) values (%s,%s,%s,%s,%s)",(drive.Caption, drive.SystemName,drive.VolumeSerialNumber,drive.VolumeName, DRIVE_TYPES[drive.DriveType]))
                    conn.commit()
                    returnvalue=cur.lastrowid
                else:
                    returnvalue=f['id']
        return returnvalue
    else:
        return []


# import pymysql
# from pymysql.cursors import DictCursor
# from GetFunctions import *
# conn = pymysql.connect(host='192.168.1.76', user="root", password="Vlado9674+", database="Duplicates", port=3307,cursorclass=DictCursor)
# cur1 = conn.cursor()
# # set_sql_mode_no_escape(cur1)
#
# cesta=r"c:\pomoc"
#
# print(disk_info(r"C:\\",conn))