Commit 2b684043 authored by Inkhey's avatar Inkhey

use generator

parent f9245714
......@@ -110,6 +110,37 @@ class sqlGit(object):
# INSERT
# DATA
def _gInsert(self,l):
for line in l:
data = line.split('[;;|\/|;;]')
yield (data)
def _gInsertFile(self,depth,mdepth):
for root, dirs, files in filtered_walk(".", depth=depth):
for fn in files:
path = os.path.join(root, fn)
size = os.path.getsize(path)
data = (fn, size, root)
yield(data)
for root, dirs, files in filtered_walk(".",
depth=depth,
min_depth=mdepth):
for d in dirs:
path = os.path.join(root, d)
size = self._get_size_dir(path)
data = (d, size, root)
yield(data)
def _gInsertLFC(self,l):
for row in l:
path = os.path.join(row[0], row[1])
cmd = 'git log --pretty=format:%H' + ' -- ' + path
log = Popen(cmd.split(), stdout=PIPE)
f = log.stdout.read().decode('utf-8', 'replace')
dLinkF_C = f.splitlines()
for commits in dLinkF_C:
data = (row[1], row[0], commits)
yield(data)
def insert_all(self, path, depth):
''' insert all content and delete unused file'''
......@@ -132,11 +163,10 @@ class sqlGit(object):
f = sort.stdout.read().decode('utf-8', 'replace')
dAuthor = f.splitlines()
c = self.conn.cursor()
for line in dAuthor:
data = line.split('[;;|\/|;;]')
c.execute(
'''INSERT INTO author(name,email)
values (?,?);''', data)
g = self._gInsert(dAuthor)
c.executemany(
'''INSERT INTO author(name,email)
values (?,?);''',g)
self.conn.commit()
@calctime
......@@ -149,11 +179,10 @@ class sqlGit(object):
f = sort.stdout.read().decode('utf-8', 'replace')
dCommit = f.splitlines()
c = self.conn.cursor()
for line in dCommit:
data = line.split('[;;|\/|;;]')
c.execute(
'''INSERT INTO commits(subject,hash,abbrev_hash,date)
values (?,?,?,?);''', data)
g = self._gInsert(dCommit)
c.executemany(
'''INSERT INTO commits(subject,hash,abbrev_hash,date)
values (?,?,?,?);''', g)
self.conn.commit()
def _get_size_dir(self,path):
......@@ -174,24 +203,10 @@ class sqlGit(object):
mdepth = None
c = self.conn.cursor()
# TODO : gérer profondeur et ignorer fichier dans .git ?
for root, dirs, files in filtered_walk(".", depth=depth):
for fn in files:
path = os.path.join(root, fn)
size = os.path.getsize(path)
data = (fn, size, root)
c.execute(
'''INSERT INTO file(name,size,dir)
values (?,?,?);''', data)
for root, dirs, files in filtered_walk(".",
depth=depth,
min_depth=mdepth):
for d in dirs:
path = os.path.join(root, d)
size = self._get_size_dir(path)
data = (d, size, root)
c.execute(
'''INSERT INTO file(name,size,dir)
values (?,?,?);''', data)
g = self._gInsertFile(depth,mdepth)
c.executemany(
'''INSERT INTO file(name,size,dir)
values (?,?,?);''', g)
self.conn.commit()
# LINKS
......@@ -205,12 +220,11 @@ class sqlGit(object):
f = log.stdout.read().decode('utf-8', 'replace')
dLinkC_A = f.splitlines()
c = self.conn.cursor()
for line in dLinkC_A:
data = line.split('[;;|\/|;;]')
c.execute(
'''INSERT INTO link_author_commits(author_name,
author_mail,commits)
values (?,?,?);''', data)
g = self._gInsert(dLinkC_A)
c.executemany(
'''INSERT INTO link_author_commits(author_name,
author_mail,commits)
values (?,?,?);''', g)
self.conn.commit()
@calctime
......@@ -221,17 +235,10 @@ class sqlGit(object):
# TODO : utiliser git show ?
c = self.conn.cursor()
c.execute("SELECT dir,name FROM file;")
for row in c.fetchall():
path = os.path.join(row[0], row[1])
cmd = 'git log --pretty=format:%H' + ' -- ' + path
log = Popen(cmd.split(), stdout=PIPE)
f = log.stdout.read().decode('utf-8', 'replace')
dLinkF_C = f.splitlines()
for commits in dLinkF_C:
data = (row[1], row[0], commits)
c.execute(
'''INSERT INTO link_file_commits(file,dir,commits)
values (?,?,?);''', data)
g = self._gInsertLFC(c.fetchall())
c.executemany(
'''INSERT INTO link_file_commits(file,dir,commits)
values (?,?,?);''', g)
self.conn.commit()
@calctime
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment