-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from avancinirodrigo/develop
Creating ecosystem feature
- Loading branch information
Showing
28 changed files
with
630 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .sqlalchemy_orm import SQLAlchemyORM, Base | ||
from .sqlalchemy_orm import SQLAlchemyORM, Base, NullSession |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .central_system import CentralSystem | ||
from .relationship import Relationship, RelationInfo | ||
from .ecosystem_analyzer import EcosystemAnalyzer | ||
from .ecosystem import Ecosystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from sqlalchemy import Column, String, Integer, ForeignKey | ||
from sqlalchemy.orm import relationship, backref | ||
from ecolyzer.dataaccess import Base | ||
|
||
class CentralSystem(Base): | ||
"""CentralSystem""" | ||
__tablename__ = 'central_system' | ||
|
||
id = Column(Integer, primary_key=True) | ||
system_id = Column(Integer, ForeignKey('system.id')) | ||
system = relationship('System', backref=backref('system', uselist=False)) | ||
|
||
def __init__(self, system): | ||
self.system = system |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from sqlalchemy import Column, String, Integer, ForeignKey | ||
from sqlalchemy.orm import relationship #, backref | ||
from ecolyzer.dataaccess import Base | ||
from .relationship import Relationship | ||
|
||
class Ecosystem(Base): | ||
"""Ecosystem""" | ||
__tablename__ = 'ecosystem' | ||
|
||
id = Column(Integer, primary_key=True) | ||
_relationships = relationship(Relationship) | ||
|
||
def add_relationship(self, relationship): | ||
self._relationships.append(relationship) | ||
|
||
def relationships(self): | ||
return self._relationships |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from ecolyzer.system import System, Call, Operation | ||
from ecolyzer.dataaccess import NullSession | ||
from .relationship import Relationship, RelationInfo | ||
|
||
class EcosystemAnalyzer(): | ||
"""EcosystemAnalyzer""" | ||
|
||
def __init__(self, ecosystem): | ||
self.ecosystem = ecosystem | ||
|
||
def make_relations(self, sys_from, sys_to, session=NullSession()): | ||
from_source_files = sys_from.source_files | ||
to_source_files = sys_to.source_files | ||
for from_fullpath, from_src_file in from_source_files.items(): | ||
from_code_elements = from_src_file.code_elements() | ||
for from_key, from_code_element in from_code_elements.items(): | ||
if isinstance(from_code_element, Call): | ||
for to_fullpath, to_src_file in to_source_files.items(): | ||
to_operation = Operation(from_code_element.name, to_src_file) | ||
if to_src_file.code_element_exists(to_operation): | ||
to_code_element = to_src_file.code_element_by_key(to_operation.key) | ||
from_info = RelationInfo(sys_from, from_src_file, from_code_element) | ||
to_info = RelationInfo(sys_to, to_src_file, to_code_element) | ||
rel = Relationship(from_info, to_info) | ||
self.ecosystem.add_relationship(rel) | ||
session.add(rel) | ||
session.expunge(to_operation) | ||
session.commit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from sqlalchemy import Column, String, Integer, ForeignKey | ||
from sqlalchemy.orm import relationship, backref | ||
from ecolyzer.dataaccess import Base | ||
#from .ecosystem import Ecosystem | ||
|
||
class Relationship(Base): | ||
"""Relationship""" | ||
__tablename__ = 'relationship' | ||
|
||
id = Column(Integer, primary_key=True) | ||
|
||
from_system_id = Column(Integer, ForeignKey('system.id')) | ||
from_system = relationship('System', foreign_keys=[from_system_id]) | ||
from_source_file_id = Column(Integer, ForeignKey('source_file.id')) | ||
from_source_file = relationship('SourceFile', foreign_keys=[from_source_file_id]) | ||
from_code_element_id = Column(Integer, ForeignKey('code_element.id')) | ||
from_code_element = relationship('CodeElement', foreign_keys=[from_code_element_id]) | ||
from_author_id = Column(Integer, ForeignKey('author.id')) | ||
from_author = relationship('Author', foreign_keys=[from_author_id]) | ||
|
||
to_system_id = Column(Integer, ForeignKey('system.id')) | ||
to_system = relationship('System', foreign_keys=[to_system_id]) | ||
to_source_file_id = Column(Integer, ForeignKey('source_file.id')) | ||
to_source_file = relationship('SourceFile', foreign_keys=[to_source_file_id]) | ||
to_code_element_id = Column(Integer, ForeignKey('code_element.id')) | ||
to_code_element = relationship('CodeElement', foreign_keys=[to_code_element_id]) | ||
to_author_id = Column(Integer, ForeignKey('author.id')) | ||
to_author = relationship('Author', foreign_keys=[to_author_id]) | ||
|
||
ecosystem_id = Column(Integer, ForeignKey('ecosystem.id')) | ||
|
||
def __init__(self, from_info, to_info): | ||
self.from_system = from_info.system | ||
self.from_source_file = from_info.source_file | ||
self.from_code_element = from_info.code_element | ||
self.from_author = from_info.author | ||
self.to_system = to_info.system | ||
self.to_source_file = to_info.source_file | ||
self.to_author = to_info.author | ||
self.to_code_element = to_info.code_element | ||
|
||
class RelationInfo(): | ||
"""RelationInfo""" | ||
def __init__(self, system, source_file, code_element): | ||
self.system = system | ||
self.source_file = source_file | ||
self.code_element = code_element | ||
self.author = code_element.author() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from git import Repo | ||
|
||
class Git: | ||
"""Git""" | ||
def __init__(self, path): | ||
self.repo = Repo(path) | ||
self.git_dir = self.repo.git_dir | ||
|
||
def commit_hashs(self, max_count=None, branch='master'): | ||
commits = list(self.repo.iter_commits(branch, max_count=max_count)) | ||
return (commit.hexsha for commit in commits) | ||
|
||
def commit_hashs_reverse(self, max_count=None, branch='master'): | ||
commits = list(self.repo.iter_commits(branch, reverse=True)) | ||
if max_count: | ||
return (commits[i].hexsha for i in range(max_count)) | ||
else: | ||
return (commit.hexsha for commit in commits) | ||
|
||
@staticmethod | ||
def IsGitRepo(path): | ||
try: | ||
Repo(path).git_dir | ||
except: | ||
return False | ||
return True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.