Exemple #1
0
def create_module(dirname, filename = '', debug = DEBUG, tgtrls = '*CURRENT', lib = DSTLIB, always = ALWAYS):
    cmd = "ADDENVVAR ENVVAR(INCLUDE) REPLACE(*YES) VALUE('" + \
          ':'.join(INCLUDE) + "')"
    os.system(cmd)
    debug = debug in (True, 'True', '1')
    dirname1 = os.path.split(dirname)[-1]
    os400.sndpgmmsg(dirname)
    # List of valid modules
    modules = set(itertools.chain(*(x[1][1] for x in SPGM)))
    modules.add('python')
    for fn in os.listdir(dirname):
        fn = fn.lower()
        if not fn.endswith('.c'):
            continue
        if not fn.startswith(filename):
            continue
        if skip(dirname1, fn):
            os400.sndpgmmsg('Skipped %s' % fn)
            continue
        modname = mangledb(fn[:-2].upper())
        if dirname1 in PREFIX and not modname.startswith(PREFIX[dirname1]):
            modname = (PREFIX[dirname1] + modname)[:10]
        if modname.lower() not in modules:
            continue
        compile(lib, modname, os.path.join(dirname, fn), debug, tgtrls, always)
Exemple #2
0
def create_pgm(lib = DSTLIB, tgtrls = '*CURRENT', always = ALWAYS):
    needlib(lib)
    if always or should_create('/QSYS.LIB/%s.LIB/PYTHON.PGM' % lib, \
      ['/QSYS.LIB/%s.LIB/PYTHON.MODULE' % lib, \
       '/QSYS.LIB/%s.LIB/PYTHON.SRVPGM' % lib]):
        os400.sndpgmmsg('Creating *pgm %s/PYTHON' % lib)
        cmd = "CRTPGM PGM(%s/PYTHON) BNDSRVPGM(%s/PYTHON) " % (lib, lib) + \
              "ALWLIBUPD(*YES) USRPRF(*OWNER) TGTRLS(%s) " % tgtrls + \
              "ACTGRP(%s) STGMDL(*TERASPACE)" % lib
        if os.system(cmd):
            os400.sndpgmmsg('*** F A I L E D ***')
Exemple #3
0
def compile(lib, modname, path, debug, tgtrls = '*CURRENT', always = ALWAYS):
    needlib(lib)
    if always or should_create('/QSYS.LIB/%s.LIB/%s.MODULE' % (lib, modname), \
      [path]):
        os400.sndpgmmsg('Compiling %s %s' % (path, debug))
        cmd = 'OPTIMIZE(40) INLINE(*ON *AUTO) DBGVIEW(*NONE)'
        if debug:
            cmd = 'OUTPUT(*PRINT) INLINE(*OFF) OPTIMIZE(10) DBGVIEW(*ALL)'
        cmd = "CRTCMOD MODULE(%s/%s) " % (lib, modname) + \
              "SRCSTMF('%s') %s " % (path, cmd) + \
              "SYSIFCOPT(*IFS64IO) LOCALETYPE(*LOCALEUTF) FLAG(10) " + \
              "TERASPACE(*YES *TSIFC) STGMDL(*TERASPACE) DTAMDL(*LLP64) " + \
              "ENUM(*INT) TGTRLS(%s)" % tgtrls
        if os.system(cmd):
            os400.sndpgmmsg('*** F A I L E D ***')
Exemple #4
0
def install_header(lib, dstpath, srcpath, file, always):
    needlib(lib)
    if not os.path.isdir('/QSYS.LIB/%s.LIB/H.FILE' % lib):
        os400.sndpgmmsg('Creating DB source file %s/H' % lib)
        cmd = "CRTSRCPF FILE(%s/H) RCDLEN(240) TEXT('Python C header files')" %\
	      (lib)
        if os.system(cmd):
            os400.sndpgmmsg('*** F A I L E D ***')
    if not os.path.isdir('%s/include' % dstpath):
        os.makedirs('%s/include' % dstpath)
    os400.sndpgmmsg('Installing header file %s/%s' % (srcpath, file))
    if always or \
      should_create('%s/include/' % dstpath, ['%s/%s' % (srcpath, file)]):
        shutil.copy2('%s/%s' % (srcpath, file), '%s/include/' % dstpath)
    mbrname = mangledb(os.path.splitext(file)[0]).upper()
    mbrpath = '/QSYS.LIB/%s.LIB/H.FILE/%s.MBR' % (lib, mbrname)
    if always or \
      should_create(mbrpath, ['%s/%s' % (srcpath, file)]):
        ofile = open(mbrpath, 'w')
        with open('%s/%s' % (srcpath, file), 'r') as ifile:
            for line in ifile:
                m = INCLUDE_RE.match(line)
                if (m):
                    line = m.group(1) + mangledb(m.group(2)) + m.group(3) + '\n'
                ofile.write(line)
        ofile.close()
Exemple #5
0
def create_srvpgm(srvpgm, lib = DSTLIB, tgtrls = '*CURRENT', always = ALWAYS):
    needlib(lib)
    srvpgm = srvpgm.lower()
    if srvpgm not in SPGMDICT:
        os400.sndpgmmsg('*** F A I L E D ***   srvpgm %s not valid' % \
                        srvpgm)
    bnds, modules = SPGMDICT[srvpgm]
    if always or \
      should_create('/QSYS.LIB/%s.LIB/%s.SRVPGM' % (lib, srvpgm), \
                    ('/QSYS.LIB/%s.LIB/%s.%s' % (lib, x, y) for (x, y) in \
                     itertools.chain(([x, 'SRVPGM'] for x in bnds), \
                                     ([x, 'MODULE'] for x in modules)))):
        os400.sndpgmmsg('Creating *srvpgm %s/%s' % (lib, srvpgm.upper()))
        cmd = "CRTSRVPGM SRVPGM(%s/%s) MODULE(" % (lib, srvpgm) + \
              ' '.join('%s/%s' % (lib, x) for x in modules) + \
              ") EXPORT(*ALL) TGTRLS(%s) ACTGRP(%s) " % (tgtrls, lib) + \
              "STGMDL(*TERASPACE) ALWLIBUPD(*YES)"
        if bnds:
            cmd += " BNDSRVPGM(" + \
                   ' '.join('%s/%s' % (lib, x) for x in bnds) + \
                   ")"
        if os.system(cmd):
            os400.sndpgmmsg('*** F A I L E D ***')
Exemple #6
0
def needlib(lib):
    if not os.path.isdir('/QSYS.LIB/%s.LIB' % lib):
        os400.sndpgmmsg('Creating library %s' % lib)
        cmd = "CRTLIB LIB(%s) TYPE(*PROD) TEXT('Python language')" % lib
        if os.system(cmd):
            os400.sndpgmmsg('*** F A I L E D ***')