48 lines
No EOL
1.5 KiB
Python
48 lines
No EOL
1.5 KiB
Python
from django.db import models
|
|
|
|
from contentmonster.classes.directory import Directory
|
|
from contentmonster.classes.vessel import Vessel
|
|
|
|
from ..validators import validate_directory
|
|
|
|
from getpass import getuser
|
|
|
|
import uuid
|
|
|
|
|
|
class ReplicationSource(models.Model):
|
|
"""Represents Directory objects in ContentMonster"""
|
|
|
|
name = models.CharField(max_length=128)
|
|
location = models.CharField(max_length=2048, validators=[validate_directory])
|
|
|
|
def to_directory(self) -> Directory:
|
|
return Directory(name, location)
|
|
|
|
|
|
class ReplicationTarget(models.Model):
|
|
"""Represents Vessel objects in ContentMonster"""
|
|
|
|
name = models.CharField(max_length=128)
|
|
address = models.CharField(max_length=256)
|
|
username = models.CharField(max_length=64, default=getuser(), null=True, blank=True)
|
|
|
|
def to_vessel(self, dbclass=None) -> Vessel:
|
|
return Vessel(name, address, username, dbclass=ContentMonsterDatabase)
|
|
|
|
|
|
class ReplicationFile(models.Model):
|
|
"""Represents File objects in ContentMonster"""
|
|
|
|
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
|
|
directory = models.ForeignKey(ReplicationSource, models.CASCADE)
|
|
name = models.CharField(max_length=128)
|
|
checksum = models.CharField(max_length=64)
|
|
|
|
|
|
class ReplicationFileLog(models.Model):
|
|
"""Represents File completion in ContentMonster"""
|
|
|
|
file = models.ForeignKey(ReplicationFile, models.CASCADE)
|
|
vessel = models.ForeignKey(ReplicationTarget, models.CASCADE)
|
|
timestamp = models.DateTimeField(auto_now_add=True) |