6
0
Dimitri Korsch 3 жил өмнө
parent
commit
7a4fc8fb3e

+ 2 - 1
migrations/versions/ece44a2b50ef_.py

@@ -23,8 +23,9 @@ def upgrade():
     sa.Column('name', sa.String(), nullable=False),
     sa.Column('description', sa.String(), nullable=True),
     sa.Column('root_folder', sa.String(), nullable=False),
+    sa.Column('configuration_file', sa.String(), nullable=False),
     sa.PrimaryKeyConstraint('id'),
-    sa.UniqueConstraint('root_folder')
+    sa.UniqueConstraint('root_folder', 'configuration_file')
     )
     op.create_table('model',
     sa.Column('id', sa.Integer(), nullable=False),

+ 5 - 1
pycs/database/Label.py

@@ -20,8 +20,12 @@ def compare_children(start_label: Label, id: int):
 
     return True
 
+def _Label_id():
+    return Label.id
+
 class Label(NamedBaseModel):
 
+
     project_id = db.Column(
         db.Integer,
         db.ForeignKey("project.id", ondelete="CASCADE"),
@@ -44,7 +48,7 @@ class Label(NamedBaseModel):
     # relationships to other models
     parent = db.relationship("Label",
         backref="children",
-        remote_side=[id],
+        remote_side=_Label_id,
     )
 
     results = db.relationship("Result",

+ 4 - 4
pycs/database/LabelProvider.py

@@ -10,14 +10,14 @@ from pycs.database.base import NamedBaseModel
 from pycs.interfaces.LabelProvider import LabelProvider as LabelProviderInterface
 
 
-def __find_files(root: str, config_regex=re.compile(r'^configuration(\d+)?\.json$')):
+def _find_files(root: str, config_regex=re.compile(r'^configuration(\d+)?\.json$')):
     # list folders in labels/
     for folder in Path(root).glob('*'):
         # list files
         for file_path in folder.iterdir():
 
             # filter configuration files
-            if not file_path.isfile():
+            if not file_path.is_file():
                 continue
 
             if config_regex.match(file_path.name) is None:
@@ -53,7 +53,7 @@ class LabelProvider(NamedBaseModel):
     @classmethod
     def discover(cls, root: Path):
 
-        for folder, conf_path in __find_files(root):
+        for folder, conf_path in _find_files(root):
             with open(conf_path) as f:
                 config = json.load(f)
 
@@ -84,7 +84,7 @@ class LabelProvider(NamedBaseModel):
             configuration = json.load(configuration_file)
 
         # load code
-        code_path = Path(self.root_folder, configuration['code']['module']).resolve()
+        code_path = str(Path(self.root_folder, configuration['code']['module']))
         module_name = code_path.replace('/', '.').replace('\\', '.')
         class_name = configuration['code']['class']
 

+ 6 - 6
pycs/database/Project.py

@@ -107,7 +107,7 @@ class Project(NamedBaseModel):
         return self.collections.filter_by(reference=reference).one_or_none()
 
     def create_label(self, name: str, reference: str = None,
-                     parent: T.Union[Label, int, str] = None, commit: bool = True) -> T.Tuple[T.Optional[Label], bool]:
+                     parent_id: T.Union[Label, int, str] = None, commit: bool = True) -> T.Tuple[T.Optional[Label], bool]:
         """
         create a label for this project. If there is already a label with the same reference
         in the database its name is updated.
@@ -118,16 +118,16 @@ class Project(NamedBaseModel):
         :return: created or edited label, insert
         """
 
-        if isinstance(parent, str):
-            parent = self.label_by_reference(parent)
+        if isinstance(parent_id, str):
+            parent_id = self.label_by_reference(parent_id)
 
-        if isinstance(parent, Label):
-            parent = parent.id
+        if isinstance(parent_id, Label):
+            parent_id = parent_id.id
 
         label, is_new = Label.get_or_create(project=self, reference=reference)
 
         label.name = name
-        label.set_parent(parent, commit=False)
+        label.set_parent(parent_id, commit=False)
 
         if commit:
             self.commit()

+ 1 - 0
pycs/database/base.py

@@ -58,6 +58,7 @@ class BaseModel(db.Model, ModelSerializer):
     def get_or_create(cls, **kwargs) -> T.Tuple[T.Any, bool]:
 
         is_new = False
+
         obj = cls.query.filter_by(**kwargs).one_or_none()
 
         if obj is None:

+ 1 - 0
test/test_database.py

@@ -35,6 +35,7 @@ class DatabaseTests(BaseTestCase):
                     name=f"Label Provider {i}",
                     description=f"Description for Label Provider {i}",
                     root_folder=f"labeldir{i}",
+                    configuration_file=f"labeldir{i}/configuration.json"
                 )
 
         # projects