Exemplo n.º 1
0
    def __init__(self, DUZ, DT, isProgrammer=False, remote=False, host='', port=9010):
        """
        """
        if DUZ is None:
            self.DUZ = "0"
        else:
            self.DUZ = DUZ
        if DT is None:
            self.DT = ""
        else:
            self.DT = DT
        self.isProgrammer = isProgrammer and True or False

        if remote:
            self.remote = FilemandClient(host, port)
            self.remote.connect(DUZ=DUZ, DT=DT, isProgrammer=isProgrammer)
        else:
            self.remote = None
Exemplo n.º 2
0
class DBS(object):

    def __init__(self, DUZ, DT, isProgrammer=False, remote=False, host='', port=9010):
        """
        """
        if DUZ is None:
            self.DUZ = "0"
        else:
            self.DUZ = DUZ
        if DT is None:
            self.DT = ""
        else:
            self.DT = DT
        self.isProgrammer = isProgrammer and True or False

        if remote:
            self.remote = FilemandClient(host, port)
            self.remote.connect(DUZ=DUZ, DT=DT, isProgrammer=isProgrammer)
        else:
            self.remote = None

    def list_files(self):
        """
            Oddly, I cannot see how to list the files using the DBS API.
            This is required for debugging etc.
        """
        if self.remote:
            return self.remote.list_files()

        M.mset('DUZ',self.DUZ)
        M.mset('U', "^")
        if self.isProgrammer:
            M.mset('DUZ(0)', "@")
        rv = []
        s0 = "0"
        while s0 != "":
            s0, name = M.mexec(
                '''set s0=$order(^DIC(s0)) Q:s0'=+s0  I $D(^DIC(s0,0))&$D(^DIC(s0,0,"GL"))&$$VFILE^DILFD(s0) S s1=$P(^DIC(s0,0),U,1)''',
                M.INOUT(s0), M.INOUT(""))
            if name:
                rv.append((name, s0))
        return rv

    def get_file(self, name, internal=True, fieldids=None, fieldnames=None):
        """
            Look up the ^DIC array and find the file number for the specified file, 
            e.g. FILE = 1 - result is a string.
        """
        if self.remote:
            return DBSFileRemote(self.remote, name, internal=internal, fieldnames=fieldnames, fieldids=fieldids)

        if name.find('::') >= 0:
            # This is a full path name to a subfile. 
            dd = DD(subfile_path=name)
        else:
            # top-level file - dd entry defines the storage.
            dd = DD(name)

        if dd.fileid is None:
            raise FilemanError("""DBS.get_file() : File not found [%s]""" % name)
        return DBSFile(dd, internal=internal, fieldids=fieldids, fieldnames=fieldnames, ext_filename=name)

    def dd(self, name):
        """
            Provided to expose the data dictionary via api
        """
        return DD(name)