Beispiel #1
0
 def __init__(self, lock, path=None):
     """ constructor initializes the lock file name """
     vars.vars()
     self.__lock = lock
     if path == None:
         self.__path = "/tmp/"
     else:
         self.__path = self.CheckPath(path)
Beispiel #2
0
 def __init__(self):
     vars.vars()
     dmercecfg = DMS.InitDmerce.NCC()
     dmercecfg.InitNCC()
     self.__sqlData = dmercecfg.InitDBConnection()
     self.__dboid = DMS.SQL.DBOID(self.__sqlData, self.__sqlData)
     self.__homeprefix = dmercecfg.GetVar('Homeprefix')
     self.__homeprefix = string.replace(self.__homeprefix, ' ', '')
     if self.__homeprefix[len(self.__homeprefix)-1] != '/':
         self.__homeprefix = self.__homeprefix + '/'
Beispiel #3
0
 def __init__(self):
     vars.vars()
     dmercecfg = DMS.InitDmerce.NCC()
     dmercecfg.InitNCC()
     self.__sqlData = dmercecfg.InitDBConnection()
     self.__instance = snmpcommands.SnmpNumeric('localhost','public') 
     self.__osname = os.uname()[0]
     self.__hostname = os.uname()[1]
     self.__dboid = DMS.SQL.DBOID(self.__sqlData, self.__sqlData)
     self.__index = []
Beispiel #4
0
def varsel(vnfile, datfile, vnfile_out, datfile_out,
           commands = '', cmd_file = None,
           **cmdsyntax):

    sx = varcmd.syntax(cmdsyntax)
    varnames = vars.vars(vnfile)
    vscmds   = varcmd.varscmds(varnames,commands,sx,cmd_file)
    vnf  = file(vnfile_out,"w")
    datf = file(datfile_out,"w")
    for (vl, dl, vcmds) in izip(file(vnfile), file(datfile), vscmds):
        if "in" in vcmds:
            vnf.write(vl)
            datf.write(dl)
Beispiel #5
0
def analynes(vnfile,
             datfile,
             typfile,
             commands=None,
             cmd_file=None,
             **cmdsyntax):

    sx = varcmd.syntax(cmdsyntax)
    vns = vars.vars(vnfile)
    vscmds = varcmd.varscmds(vns, commands, sx, cmd_file, ("addval", "delval"))

    for (vcmds, dl, tl) in izip(vscmds, file(datfile), file(typfile)):
        yield analyne(dl, tl, vcmds.get('addval', []))
Beispiel #6
0
def varcheck(vnfile, nof_vars=None):

    varnames = vars.vars(vnfile)
    lenvars = len(varnames)
    dups = len(set(varnames)) < lenvars

    if dups:
        while varnames:
            vn = varnames.pop(0)
            if vn in varnames:
                return (False, "Variable name %s occurs twice." % vn)

    if nof_vars != None and lenvars != nof_vars:
        msg = "Expected %d variable names, but got %d." % (nof_vars, lenvars)
        return (False, msg)

    return (True, "OK")
Beispiel #7
0
def misrep(vnfile,
           datfile,
           repfile,
           commands=None,
           cmd_file=None,
           miss_mark="",
           **cmdsyntax):

    sx = varcmd.syntax(cmdsyntax)
    vns = vars.vars(vnfile)
    cmds = varcmd.prepend(sx, "miss " + miss_mark, commands)
    vscmds = varcmd.varscmds(vns, cmds, sx, cmd_file, ("miss", ))

    repf = repfile == "-" and sys.stdout or file(repfile, "w")

    for (vcmds, dl) in izip(vscmds, file(datfile)):
        acs = vcmds['miss']
        nof_mvals = sum(int(d.strip() in acs) for d in dl[:-1].split("\t"))
        print >> repf, nof_mvals
Beispiel #8
0
def diz(vnfile, dfn, anafile, typfile, resdn,
        commands      = "",  cmd_file      = None,
        Imputation    = None, Limits = False,
        **sx ):

    diradd = lambda x : os.path.join(resdn, x)

    outfs = {}
    for outfn in "dsp vds hst dzd".split():
        outfs[outfn] = file(diradd(outfn),"w")

    vns = vars.vars(vnfile)
    sx = varcmd.syntax(sx)

    if Imputation:
        commands = varcmd.prepend(sx, "IMP %s" % Imputation, commands)

    positive = ("DIS","IMP", "addval", "delval")
    vscmds = varcmd.varscmds(vns, commands, sx, cmd_file, positive)

    for (vn, vcmd, l, ana, tl) in izip(vns, vscmds, file(dfn),
                                       fanas(anafile), file(typfile)):
        lin(vn, l, ana, tl, vcmd['DIS'], vcmd.get('IMP', None), Limits, outfs)
Beispiel #9
0
        fresh = []
        for i in tables:
            fresh.append(i[dictKey])
        return fresh

    def CleanORACLE(self, tables):
        """ cleans the returned value of all tables in a Oracle DB"""
        dictKey = 'TABLE_NAME'
        fresh = []
        for i in tables:
            fresh.append(i[dictKey])
        return fresh

if __name__=='__main__':
    """ initialize needed dmerce vars """
    vars.vars()
    """ make an instance of funcion class we need """
    f = Function()
    table = ''
    """ beginn with input form """
    dbtype = string.upper(string.strip(raw_input('Enter dbtype (oracle, mysql): ')))
    database = string.strip(raw_input('Enter name of database: '))
    user = string.strip(raw_input('Enter database user: '******'Enter the password for given db user: '******'Change tables [a = all | l = seperated list | f = file]: ')))
    if all == 'F':
        inputFile = (raw_input('Enter complete path to file: '))
    """ look if a valid dbtype is given, if not exit program """
    if dbtype != 'ORACLE' and dbtype != 'MYSQL':
        print '\nSorry, your given dbtype', dbtype ,'! is not valid.\n\n Please try again !!!\n'
        sys.exit()
Beispiel #10
0
 def main(vnfile, commands="", cmd_file=None, **sx):
     sx = syntax(sx)
     vns = vars.vars(vnfile)
     for t in varscmds(vns, commands, sx, cmd_file):
         print t
Beispiel #11
0
def din(datafile,
        resdir,
        delim=None,
        rowise=False,
        names="ROW",
        start=0,
        keep_empty=False,
        tabstring=None,
        commands='',
        cmd_file=None,
        missmark="",
        **cmdsyntax):

    # ENSURE RESDIR

    if not os.path.exists(resdir) or not os.path.isdir(resdir):
        os.makedirs(resdir)

    # HELPERS

    dad = lambda x: os.path.join(resdir, x)
    dtns = lambda phase: dad(os.path.basename(datafile)) + "_" + phase

    def clean(fn):
        if not DBG_KEEP: os.remove(fn)

    # START BY

    shutil.copyfile(datafile, dtns("org"))

    if delim and len(delim) == 3 and delim.isdigit():
        delim = chr(int(delim, 8))

    # CHECK IT

    (ok, nof_rows, nof_cols, msg) = formatcheck(dtns("org"), delim, keep_empty)

    if not ok:
        return (0, nof_rows, nof_cols, msg)

    # TABIFY

    table2tab_le(dtns("org"), dtns("tab"), delim, keep_empty, tabstring)
    clean(dtns("org"))

    # VARS

    vnfn = dad("vns.org")
    if names == "GEN":
        vargen(rowise and nof_rows or nof_cols, vnfn, start)
        shutil.copyfile(dtns("tab"), dtns("nov"))
    elif names in ("ROW", "COL"):
        split2var_n_dat(dtns("tab"), vnfn, dtns("nov"), names)
    else:
        shutil.copyfile(names, vnfn)
        shutil.copyfile(dtns("tab"), dtns("nov"))

    ok, msg = varcheck(vnfn, rowise and nof_rows or nof_cols)
    if not ok:
        return (0, nof_rows, nof_cols, msg)

    clean(dtns("tab"))

    # VAR/ROW

    if rowise:
        N = nof_cols
        shutil.copyfile(dtns("nov"), dtns("org"))
    else:
        transpose(dtns("nov"), dtns("col"), "\t")
        N = nof_rows

    clean(dtns("nov"))

    # SEL

    sx = varcmd.syntax(cmdsyntax)
    new_vnfn = dad("vns")
    varsel(vnfn, dtns("col"), new_vnfn, dtns("sel"), commands, cmd_file, **sx)
    vnfn = new_vnfn
    nof_vars = len(vars.vars(vnfn))
    clean(dtns("col"))

    # MIS

    msfn = dad("mis")

    misrep(vnfn, dtns("sel"), msfn, commands, cmd_file, missmark, **sx)

    mismark(vnfn, dtns("sel"), dtns("mis"), commands, cmd_file, missmark, **sx)

    clean(dtns("sel"))

    # TYP

    tpfn = dad("typ")
    datyp(dtns("mis"), tpfn)

    # ANA -- should this be here or not

    anfn = dad("ana")
    datana(vnfn, dtns("mis"), tpfn, anfn, commands, cmd_file, **sx)

    # DNA

    shutil.copyfile(dtns("mis"), dad("dna"))
    clean(dtns("mis"))

    return (1, N, nof_vars, msg)