Commit 3164f45e authored by inkhey's avatar inkhey

subprocess+ better split value

parent 2864580f
......@@ -11,11 +11,11 @@
import sqlite3
import os
from subprocess import Popen, PIPE
from walkdir import filtered_walk, all_paths
# use walkir instead of os.walk to be able
# to select a depth
class sqlGit(object):
''' Transform Git data into sqlite database to
analyse these datas into program like gephi'''
......@@ -86,11 +86,15 @@ class sqlGit(object):
def insert_author(self):
''' insert author data into author table'''
f = os.popen("git log --format='%aN;;%aE'| sort -u")
dAuthor = f.read().splitlines()
log = Popen("git log --format=%aN;;;;%aE".split(), stdout=PIPE)
sort = Popen("sort -u".split(), stdin=log.stdout, stdout=PIPE)
log.stdout.close()
f = sort.stdout.read().decode('utf-8','replace')
dAuthor = f.splitlines()
c = self.conn.cursor()
for line in dAuthor:
data = line.split(';;')
data = line.split(';;;;')
c.execute(
'''INSERT INTO author(name,email)
values (?,?);''', data)
......@@ -98,13 +102,15 @@ class sqlGit(object):
def insert_commit(self):
''' insert commit data into commits table'''
f = os.popen("git log --format='%s;;%H;;%t;;%at' | sort -u")
dCommit = f.read().splitlines()
log = Popen("git log --format=%s;;;;%H;;;;%t;;;;%at".split(), stdout=PIPE)
sort = Popen("sort -u".split(), stdin=log.stdout, stdout=PIPE)
log.stdout.close()
f = sort.stdout.read().decode('utf-8','replace')
dCommit = f.splitlines()
c = self.conn.cursor()
i = 0
for line in dCommit:
data = line.split(';;')
data = line.split(';;;;')
c.execute(
'''INSERT INTO commits(subject,hash,abbrev_hash,date)
values (?,?,?,?);''', data)
......@@ -144,12 +150,13 @@ class sqlGit(object):
''' insert link data between author and commit into
link_author_commits table'''
f = os.popen('git log --pretty=format:"%aN;;%aE;;%H"')
dLinkC_A = f.read().splitlines()
log = Popen('git log --pretty=format:%aN;;;;%aE;;;;%H'.split(), stdout=PIPE)
f = log.stdout.read().decode('utf-8','replace')
dLinkC_A = f.splitlines()
c = self.conn.cursor()
i = 0
for line in dLinkC_A:
data = line.split(';;')
data = line.split(';;;;')
c.execute(
'''INSERT INTO link_author_commits(author_name,
author_mail,commits)
......@@ -165,8 +172,10 @@ class sqlGit(object):
c.execute("SELECT dir,name FROM file;")
for row in c.fetchall():
path = os.path.join(row[0], row[1])
f = os.popen('git log --pretty=format:"%H"' + ' -- ' + path)
dLinkF_C = f.read().splitlines()
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(
......
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