Ejemplo n.º 1
0
    def __init__(self):
        self.scontext = SContext()

        self.filepath = None

        self.imagery = Imagery(self)

        self.stackup = Stackup(self)
        self.artwork = Artwork(self)

        self.nets = Nets(self)
Ejemplo n.º 2
0
    def __init__(self) -> None:
        self.scontext = SContext()

        self.filepath: Optional[str] = None

        self.imagery = Imagery(self)

        self.stackup = Stackup(self)
        self.artwork = Artwork(self)

        self.nets = Nets(self)
Ejemplo n.º 3
0
    def __init__(self):
        self.scontext = SContext()

        self.filepath = None

        self.imagery = Imagery(self)

        self.stackup = Stackup(self)
        self.artwork = Artwork(self)

        self.nets = Nets(self)
Ejemplo n.º 4
0
class Project:

    def __init__(self):
        self.scontext = SContext()

        self.filepath = None

        self.imagery = Imagery(self)

        self.stackup = Stackup(self)
        self.artwork = Artwork(self)

        self.nets = Nets(self)

    @property
    def can_save(self):
        return self.filepath is not None

    @staticmethod
    def create():
        pass
        return Project()

    def _serialize(self):
        project = ser.Project.new_message()
        project.stackup = self.stackup.serialize()
        project.imagery = self.imagery.serialize()
        project.nets = self.nets.serialize()
        project.artwork = self.artwork.serialize()

        return project

    @staticmethod
    def _deserialize(msg):
        p = Project()
        with p.scontext.restoring():
            p.stackup.deserialize(msg.stackup)
            p.imagery.deserialize(msg.imagery)
            p.nets.deserialize(msg.nets)
            p.artwork.deserialize(msg.artwork)
        return p

    @staticmethod
    def open(path):
        f = open(path, "rb", buffering=0)
        self = Project.open_fd(f)
        self.filepath = path

        return self

    @staticmethod
    def open_fd(fd):
        magic = fd.read(8)
        if magic[:6] != MAGIC:
            raise ValueError("Unknown File Type")

        vers = magic[6:8]
        if vers != VERSION_MAGIC:
            raise ValueError("Unknown File Version")

        _project = ser.Project.read(fd)
        self = Project._deserialize(_project)
        return self

    def save_fd(self, fd):
        fd.write(MAGIC + VERSION_MAGIC)

        message = self._serialize()
        message.write(fd)

    def save(self, path=None, update_path=False):
        if path is None:
            path = self.filepath

        if path is None:
            raise ValueError("Must have either a filename, or a save-as path")

        bakname = path + ".bak"
        try:
            bakname = path + ".bak"

            if os.path.exists(bakname):
                os.unlink(bakname)

            if os.path.exists(path):
                os.rename(path, bakname)
        except (IOError, OSError):
            raise IOError("Couldn't manipulate backup file")

        f = open(path, "w+b", buffering=0)
        try:
            self.save_fd(f)
        except Exception as e:
            os.unlink(path)
            os.rename(bakname, path)
            raise

        if update_path:
            self.filepath = path

        f.flush()
        f.close()


    def close(self):
        pass
Ejemplo n.º 5
0
class Project:
    def __init__(self):
        self.scontext = SContext()

        self.filepath = None

        self.imagery = Imagery(self)

        self.stackup = Stackup(self)
        self.artwork = Artwork(self)

        self.nets = Nets(self)

    @property
    def can_save(self):
        return self.filepath is not None

    @staticmethod
    def create():
        pass
        return Project()

    def _serialize(self):
        project = ser.Project.new_message()
        project.stackup = self.stackup.serialize()
        project.imagery = self.imagery.serialize()
        project.nets = self.nets.serialize()
        project.artwork = self.artwork.serialize()

        return project

    @staticmethod
    def _deserialize(msg):
        p = Project()
        with p.scontext.restoring():
            p.stackup.deserialize(msg.stackup)
            p.imagery.deserialize(msg.imagery)
            p.nets.deserialize(msg.nets)
            p.artwork.deserialize(msg.artwork)
        return p

    @staticmethod
    def open(path):
        f = open(path, "rb", buffering=0)
        self = Project.open_fd(f)
        self.filepath = path

        return self

    @staticmethod
    def open_fd(fd):
        magic = fd.read(8)
        if magic[:6] != MAGIC:
            raise ValueError("Unknown File Type")

        vers = magic[6:8]
        if vers != VERSION_MAGIC:
            raise ValueError("Unknown File Version")

        _project = ser.Project.read(fd)
        self = Project._deserialize(_project)
        return self

    def save_fd(self, fd):
        fd.write(MAGIC + VERSION_MAGIC)

        message = self._serialize()
        message.write(fd)

    def save(self, path=None, update_path=False):
        if path is None:
            path = self.filepath

        if path is None:
            raise ValueError("Must have either a filename, or a save-as path")

        bakname = path + ".bak"
        try:
            bakname = path + ".bak"

            if os.path.exists(bakname):
                os.unlink(bakname)

            if os.path.exists(path):
                os.rename(path, bakname)
        except (IOError, OSError):
            raise IOError("Couldn't manipulate backup file")

        f = open(path, "w+b", buffering=0)
        try:
            self.save_fd(f)
        except Exception as e:
            os.unlink(path)
            os.rename(bakname, path)
            raise

        if update_path:
            self.filepath = path

        f.flush()
        f.close()

    def close(self):
        pass