-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaal_polta_fs_listing_main_driver_SQLite.py
More file actions
96 lines (62 loc) · 2.91 KB
/
aal_polta_fs_listing_main_driver_SQLite.py
File metadata and controls
96 lines (62 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os, sys
import datetime
import sqlite3
#radius_driveFIleCount_vFSz.py
#gTargetDriveStr = 'C:\\Users\\mlashkar\\U_Drive_Backup\\PY_HOME\\radius_projects\\storage_survey'
#gTargetDriveStr = '/home/sas/HOME_PY'
gTargetDriveStr = '~/palashworld/_dev/HOME_PY/syncDir'
db_loc_1 = 'aal_polta_fs_listing_DB.sqlite'
def isLinux():
print("In IsLinux")
if sys.platform == 'win32':print("win32")
if os.environ.get('OS','') == 'Windows_NT':print("winNT")
if os.name == 'nt':print("nt")
class FILE_DETAILS_CLS:
def __init__ (self):
self.filename= None # or whatever
self.fullpath = None
self.size_in_KB = None
self.last_mod_dt = None
self.extn = None
def printContent(self):
print ( '\n filename =' , self.filename, '\n fullpath =' , self.fullpath,'\n size_in_KB =' , self.size_in_KB, '\n self.last_mod_dt =' , self.last_mod_dt , '\n Extension =' , self.extn)
def listToPathString ( pList) :
return ''.join((str(e)+'\\') for e in pList)
def loadInto_DRIVE_DETAILS_DB ( pTableDataStrct ):
conn = sqlite3.connect(db_loc_1)
cur = conn.cursor()
sql_query = "insert into DRIVE_DETAILS (FILENAME, FULLPATH, FILESIZE, LAST_MOD_DT, FILEEXT ) values (?, ?, ?, ?, ?)"
sql_data = (pTableDataStrct.filename, pTableDataStrct.fullpath, pTableDataStrct.size_in_KB, pTableDataStrct.last_mod_dt, pTableDataStrct.extn)
try:
cur.execute(sql_query, sql_data)
conn.commit()
except sqlite3.Error as er:
print ( 'Error = ', er)
#self.output_exc()
cur.close()
def countDriveFiles ( pDrivePathStr):
print ("Surveying path : " + pDrivePathStr + " , for file attributes....." )
dir_count = 0
file_count = 0
fullPath = ''
isLinux()
for root, dirs, files in os.walk(pDrivePathStr):
file_deatils_obj = FILE_DETAILS_CLS()
dir_count += len(dirs)
file_count += len(files)
path = root.split(os.sep)
lev1 = listToPathString(path)
for file in files:
fullPath = os.path.join(root, file)
file_deatils_obj.filename = file
file_deatils_obj.fullpath = (lev1 + file).replace(' ','')
file_deatils_obj.extn = os.path.splitext(file_deatils_obj.fullpath)[1]
file_deatils_obj.size_in_KB = format (os.stat(fullPath).st_size, '.2f')
file_deatils_obj.last_mod_dt = datetime.datetime.fromtimestamp(os.stat(fullPath).st_mtime)
file_deatils_obj.printContent()
loadInto_DRIVE_DETAILS_DB ( file_deatils_obj)
print ("\nDrive path survey co " , pDrivePathStr)
print ("\nDir_count = ", dir_count )
print ("\nFile_count = ", file_count )
countDriveFiles (gTargetDriveStr)
#print time.ctime(max(os.stat(root).st_mtime for root,_,_ in os.walk('/tmp/x'))):