示例#1
0
def find_global_program(name):
    assert name != "source", "Do not use source, run .sh files instead."
    program_path = plcommand(name)

    if program_path is None:
        wlines = toolkit.command_output("which %s" % name)
        if len(wlines) != 1:
            raise core.PyTestUsageError(
                "The only global programs currently supported are those found by 'which' "
                "or those found in a <plearn_branch>/commands/. Call 'which %s' resulted "
                "in those %d lines \n%s" %
                (name, len(wlines), ''.join(wlines)))

        path = wlines[0]
        path = path.rstrip(' \n')
        if sys.platform == 'win32':
            # Need to convert the Cygwin path to the Windows path, otherwise
            # os.path.exists(path) will return False.
            path = toolkit.command_output("cygpath -w %s" % path)
            path = path[0].rstrip('\n')
        if toolkit.exec_path_exists(path):
            program_path = os.path.abspath(path)

    assert program_path is not None, 'Could not find global program %s' % name
    return program_path
示例#2
0
def getIndentedScripts(pyplearn_path, indent):
    # Reading file from script and indenting
    indented_pyscript = ""
    pyplearn_script = open(pyplearn_path, 'r')

    first = True
    for line in pyplearn_script:
        if first:
            indented_pyscript += line
            first = False
        else:
            indented_pyscript += indent + line
    pyplearn_script.close()

    # Parsing the script using the pyplearn_driver
    indented_plscript = ""
    plearn_script = toolkit.command_output("pyplearn_driver.py %s" %
                                           pyplearn_path)
    first = True
    for line in plearn_script:
        if first:
            indented_plscript += line
            first = False
        else:
            indented_plscript += indent + line

    return indented_pyscript, indented_plscript
示例#3
0
文件: Tutorial.py 项目: deccs/PLearn
def getIndentedScripts( pyplearn_path, indent ):
    # Reading file from script and indenting
    indented_pyscript = ""
    pyplearn_script = open( pyplearn_path, 'r' )

    first = True
    for line in pyplearn_script:
        if first:
            indented_pyscript += line
            first = False
        else:            
            indented_pyscript += indent + line
    pyplearn_script.close()

    # Parsing the script using the pyplearn_driver
    indented_plscript = ""
    plearn_script   = toolkit.command_output( "pyplearn_driver.py %s" %
                                              pyplearn_path )
    first = True
    for line in plearn_script:
        if first:
            indented_plscript += line
            first = False
        else:
            indented_plscript += indent + line

    return indented_pyscript, indented_plscript
示例#4
0
文件: programs.py 项目: deccs/PLearn
 def invoke(self, arguments, logfname):
     if self.isPLearnCommand() and not self.no_plearn_options:            
         # arguments = "--no-version %s"%arguments
         arguments = "--no-version --no-progress %s"%arguments
     #command = '%s %s >& %s'%(self.getInternalExecPath(), arguments, logfname)
     command = '%s %s' % (self.getInternalExecPath(), arguments)
     # Run the test.
     logging.debug("In %s: %s"%(os.getcwd(), command))
     test_output = toolkit.command_output(command)
     # Save test output into log file.
     logfile = open(logfname, 'w')
     logfile.writelines(test_output)
     logfile.close()
     if sys.platform == "win32":
         # Need to convert Windows line feeds to Unix ones, otherwise the
         # diff will fail when comparing expected and actual run logs.
         toolkit.command_output("dos2unix %s" % logfname)
示例#5
0
 def invoke(self, arguments, logfname):
     if self.isPLearnCommand() and not self.no_plearn_options:
         # arguments = "--no-version %s"%arguments
         arguments = "--no-version --no-progress %s" % arguments
     #command = '%s %s >& %s'%(self.getInternalExecPath(), arguments, logfname)
     command = '%s %s' % (self.getInternalExecPath(), arguments)
     # Run the test.
     logging.debug("In %s: %s" % (os.getcwd(), command))
     test_output = toolkit.command_output(command)
     # Save test output into log file.
     logfile = open(logfname, 'w')
     logfile.writelines(test_output)
     logfile.close()
     if sys.platform == "win32":
         # Need to convert Windows line feeds to Unix ones, otherwise the
         # diff will fail when comparing expected and actual run logs.
         toolkit.command_output("dos2unix %s" % logfname)
示例#6
0
文件: pldiff.py 项目: zbxzc35/PLearn
def vmatdiff(former_file, later_file, precision):
    logging.debug("--- vmatdiff %s %s %g"%(former_file, later_file, precision))
    diffcmd = plearn_cmd('vmat diff %s %s %g')%(former_file, later_file, precision)
    diffoutput = toolkit.command_output(diffcmd)

    if diffoutput:
        return [ diffcmd ] + [ (' '*4)+line for line in diffoutput ]
    return []
示例#7
0
文件: core.py 项目: zbxzc35/PLearn
 def vsystem(cmd, display_cmd=''):
     if display_cmd == '':
         display_cmd = cmd
     print >> sys.stderr, '#\n#  %s\n#' % display_cmd
     sys.stderr.flush()
     stderr_output = toolkit.command_output(cmd, True, False)
     if stderr_output:
         print >> sys.stderr, stderr_output[0].rstrip('\n')
     print >> sys.stderr, ''
     sys.stderr.flush()
示例#8
0
文件: core.py 项目: deccs/PLearn
 def vsystem(cmd, display_cmd = ''):        
     if display_cmd == '':
         display_cmd = cmd
     print >>sys.stderr, '#\n#  %s\n#' % display_cmd
     sys.stderr.flush()
     stderr_output = toolkit.command_output(cmd, True, False)
     if stderr_output:
         print >>sys.stderr, stderr_output[0].rstrip('\n')
     print >>sys.stderr, ''
     sys.stderr.flush()
示例#9
0
文件: pldiff.py 项目: zbxzc35/PLearn
def psavediff(former_file, later_file, precision=1e-06):
    """Special manipulation of psave files.
    
    The psave files are meant to change over time which additions of
    new options to the various class of the library. To avoid a diff to
    fail on the addition of a new option, the psave files are canonized
    through the read_and_write command prior to the diff call.
    """
    # Absolute path to the original files
    former_abspath = os.path.abspath(former_file)
    later_abspath = os.path.abspath(later_file)

    # Creating and changing to a temporary directory meant for comparison
    tmpdir = 'PSAVEDIFF/%s'%os.path.basename(later_file)
    if not os.path.exists(tmpdir):
        os.makedirs(tmpdir)
    moresh.pushd( tmpdir )
    logging.debug("--- pushd to %s"%os.getcwd())

    # Names for the files resulting from read_and_write
    former_rw = "rw_former_%s"%os.path.basename(former_file)
    later_rw = "rw_later_%s"%os.path.basename(later_file)

    # Creating the canonized files
    rw_cmd = plearn_cmd("read_and_write %s %s")
    os.system( rw_cmd%(former_abspath, former_rw) )
    assert os.path.exists(former_rw), "Error generating %s"%former_rw
    logging.debug(rw_cmd%(former_abspath, former_rw)+' succeeded.')

    os.system( rw_cmd%(later_abspath, later_rw) )
    assert os.path.exists(later_rw), "Error generating %s"%later_rw
    logging.debug(rw_cmd%(later_abspath, later_rw)+' succeeded.')

    ## Actual comparison
    report = []
    diff = toolkit.command_output(plearn_cmd("diff %s %s %s") \
                          % (former_rw, later_rw, precision))
    diff = "".join(diff)
    # diff = toldiff(former_rw, later_rw, precision)

    if diff:
        report = [ "--- %s and %s\n  Processed through read_and_write (%s)\n     %s"
                   % (former_file, later_file, tmpdir, diff) ]
    logging.debug('Report: %s'%report)

    ## Move back to original directory.
    moresh.popd( )
    logging.debug("--- popd to %s\n"%os.getcwd())
    return report
示例#10
0
文件: programs.py 项目: deccs/PLearn
def find_global_program(name):
    assert name != "source", "Do not use source, run .sh files instead."
    program_path = plcommand(name)

    if program_path is None:
        wlines = toolkit.command_output( "which %s"%name )
        if len(wlines) != 1:
            raise core.PyTestUsageError(
                "The only global programs currently supported are those found by 'which' "
                "or those found in a <plearn_branch>/commands/. Call 'which %s' resulted "
                "in those %d lines \n%s"%(name, len(wlines), ''.join(wlines)) )

        path = wlines[0]
        path = path.rstrip(' \n')
        if sys.platform == 'win32':
            # Need to convert the Cygwin path to the Windows path, otherwise
            # os.path.exists(path) will return False.
            path = toolkit.command_output( "cygpath -w %s" % path )
            path = path[0].rstrip('\n')
        if toolkit.exec_path_exists(path):
            program_path = os.path.abspath(path)

    assert program_path is not None, 'Could not find global program %s' % name
    return program_path
示例#11
0
文件: core.py 项目: zbxzc35/PLearn
    import os
    from plearn.pytest import modes
    from plearn.utilities.ModeAndOptionParser import Mode

    def vsystem(cmd, display_cmd=''):
        if display_cmd == '':
            display_cmd = cmd
        print >> sys.stderr, '#\n#  %s\n#' % display_cmd
        sys.stderr.flush()
        stderr_output = toolkit.command_output(cmd, True, False)
        if stderr_output:
            print >> sys.stderr, stderr_output[0].rstrip('\n')
        print >> sys.stderr, ''
        sys.stderr.flush()

    if sys.platform == 'win32':
        which_pytest = toolkit.command_output('which pytest')[0].rstrip('\n')
        pytest_cmd = \
            toolkit.command_output('cygpath -w %s'%which_pytest)[0].rstrip('\n')
        pytest_cmd = 'python ' + pytest_cmd
    else:
        pytest_cmd = 'pytest'

    vsystem(pytest_cmd, 'pytest')
    vsystem('%s -h' % pytest_cmd, 'pytest -h')

    for mode in Mode.mode_list():
        mode_name = mode.__name__
        vsystem('%s %s -h' % (pytest_cmd, mode_name),
                'pytest %s -h' % mode_name)
示例#12
0
# A hack to use StatsCollector.py without needing a symbolic link.

import os, sys
from plearn.utilities import toolkit

homedir = os.environ.get('HOME', '/')
plearndir = os.environ.get('PLEARNDIR', os.path.join(homedir, 'PLearn'))

full_path = os.path.join(plearndir, 'python_modules', 'plearn', 'math', \
                         'StatsCollector.py')

if sys.platform == 'win32':
    full_path = toolkit.command_output("cygpath -w %s" % full_path)
    full_path = full_path[0].rstrip('\n')

execfile(full_path)
示例#13
0
# A hack to use StatsCollector.py without needing a symbolic link.

import os, sys
from plearn.utilities import toolkit

homedir = os.environ.get('HOME', '/')
plearndir = os.environ.get('PLEARNDIR', os.path.join(homedir,'PLearn'))

full_path = os.path.join(plearndir, 'python_modules', 'plearn', 'math', \
                         'StatsCollector.py')

if sys.platform == 'win32':
    full_path = toolkit.command_output("cygpath -w %s" % full_path)
    full_path = full_path[0].rstrip('\n')

execfile(full_path)

示例#14
0
文件: core.py 项目: deccs/PLearn
    import os
    from plearn.pytest import modes
    from plearn.utilities.ModeAndOptionParser import Mode

    def vsystem(cmd, display_cmd = ''):        
        if display_cmd == '':
            display_cmd = cmd
        print >>sys.stderr, '#\n#  %s\n#' % display_cmd
        sys.stderr.flush()
        stderr_output = toolkit.command_output(cmd, True, False)
        if stderr_output:
            print >>sys.stderr, stderr_output[0].rstrip('\n')
        print >>sys.stderr, ''
        sys.stderr.flush()
        
    if sys.platform == 'win32':
        which_pytest = toolkit.command_output('which pytest')[0].rstrip('\n')
        pytest_cmd = \
            toolkit.command_output('cygpath -w %s'%which_pytest)[0].rstrip('\n')
        pytest_cmd = 'python ' + pytest_cmd
    else:
        pytest_cmd = 'pytest'

    vsystem(pytest_cmd, 'pytest')
    vsystem('%s -h' % pytest_cmd, 'pytest -h')

    for mode in Mode.mode_list():
        mode_name = mode.__name__
        vsystem('%s %s -h' % (pytest_cmd, mode_name),'pytest %s -h' % mode_name)