예제 #1
0
def testStorage(path, readonly=False, hadd=True, verb=0):

    # INITIALIZE
    LOG.header("__init__")
    #storage = ensuremodule(system,"PicoProducer.storage"
    storage = getstorage(path, ensure=True, verb=verb)
    print ">>> %r" % (storage)
    print ">>> %-10s = %s" % ('path', storage.path)
    print ">>> %-10s = %s" % ('rmcmd', storage.rmcmd)
    print ">>> %-10s = %s" % ('lscmd', storage.lscmd)
    print ">>> %-10s = %s" % ('mkdrcmd', storage.mkdrcmd)
    print ">>> %-10s = %s" % ('cpcmd', storage.cpcmd)
    print ">>> %-10s = %s" % ('tmpdir', storage.tmpdir)
    print ">>> "

    # EXPAND PATH
    LOG.header("expandpath")
    pathargs = [
        ('test.py', ),
        ('$PATH/test.py', ),
        (
            'foo',
            'bar',
        ),
    ]
    pathkwargs = [
        {
            'here': True
        },
        {
            'here': False
        },
    ]
    for patharg in pathargs:
        for pathkwarg in pathkwargs:
            LOG.color("storage.expandpath(%s,%s)" %
                      (','.join(repr(a) for a in patharg), ','.join(
                          "%s=%r" % (k, v) for k, v in pathkwarg.iteritems())))
            result = storage.expandpath(*patharg, **pathkwarg)
            print ">>>   %r" % (result)

    # LS
    LOG.header("ls")
    LOG.color("storage.ls(verb=%d)" % (verb))
    contents = storage.ls(verb=verb)
    print ">>> Found %d items" % (len(contents))
    print ">>> Contents: %s" % (contents)

    # FILES
    LOG.header("getfiles")
    LOG.color("storage.getfiles(verb=%d)" % (verb))
    contents = storage.getfiles(verb=verb)
    print ">>> Found %d items" % (len(contents))
    print ">>> Contents: %s" % (contents)
    print ">>> "
    LOG.color("storage.getfiles(filter='*.*',verb=%d)" % (verb))
    contents = storage.getfiles(filter='*.*', verb=verb)
    print ">>> Found %d files" % (len(contents))
    print ">>> Contents: %s" % (contents)
    print ">>> "
    LOG.color("storage.getfiles(filter='*.*',url=None,verb=%d)" % (verb))
    contents = storage.getfiles(filter='*.*', url=None, verb=verb)
    print ">>> Found %d files" % (len(contents))
    print ">>> Contents: %s" % (contents)

    if readonly:
        print ">>> Read only. Skip test for cp, rm, mkdir, hadd..."
        return

    # CP
    LOG.header("cp")
    fname = createdummy("testStorage.txt")
    LOG.color("storage.cp(%r,verb=%d)" % (fname, verb))
    storage.cp(fname, verb=verb)
    storage.ls(verb=verb)

    # EXISTS
    LOG.header("exists")
    LOG.color("storage.exists(%r,verb=%d)" % (fname, verb))
    result = storage.exists(fname, verb=verb)
    print ">>> Exists: %r" % (result)
    storage.ls(verb=verb)

    # RM
    LOG.header("rm")
    LOG.color("storage.rm(%r,verb=%d)" % (fname, verb))
    try:
        storage.rm(fname, verb=verb)
    except Exception as error:
        print error
    storage.ls(verb=verb)

    # MKDIR
    LOG.header("mkdir")
    dirname = 'test'
    LOG.color("storage.mkdir(%r.verb=%d)" % (dirname, verb))
    try:
        storage.mkdir(dirname, verb=verb)
        storage.ls(verb=verb)
        storage.ls(dirname, here=True, verb=verb)
        result = storage.exists(dirname, verb=verb)
        print ">>> Exists: %r" % (result)
    except Exception as error:
        print error

    # RM DIRECTORY
    LOG.header("rm directory")
    submit = raw_input(">>> Careful! Do you really want to remove %r? [y/n] " %
                       (storage.expandpath(dirname, here=True)))
    if submit == 'y':
        LOG.color("storage.rm(%r,verb=%d)" % (dirname, verb))
        try:
            storage.rm(dirname, verb=verb)
            storage.ls(verb=verb)
        except Exception as error:
            print error

    # HADD
    if hadd:
        LOG.header("hadd")
        infiles = [
            createdummyroot("testStorage1.root"),
            createdummyroot("testStorage2.root")
        ]
        outfile = "testStorage.root"
        for tmpdir in [
                True,
        ]:  #False
            LOG.color("storage.hadd(%r,%r,tmpdir=%s,verb=%d)" %
                      (infiles, outfile, tmpdir, verb))
            try:
                storage.hadd(infiles, outfile, tmpdir=tmpdir, verb=verb)
                storage.ls(verb=verb)
                storage.rm(outfile, verb=verb)
            except Exception as error:
                print error
예제 #2
0
def testStorage(path,verb=0):
  
  # INITIALIZE
  LOG.header("__init__")
  #storage = ensuremodule(system,"PicoProducer.storage"
  storage = getstorage(path,ensure=True,verb=verb)
  print ">>> %r"%(storage)
  print ">>> %-10s = %s"%('path',storage.path)
  print ">>> %-10s = %s"%('rmcmd',storage.rmcmd)
  print ">>> %-10s = %s"%('lscmd',storage.lscmd)
  print ">>> %-10s = %s"%('mkdrcmd',storage.mkdrcmd)
  print ">>> %-10s = %s"%('cpcmd',storage.cpcmd)
  print ">>> %-10s = %s"%('tmpdir',storage.tmpdir)
  print ">>> "
  
  # EXPAND PATH
  LOG.header("expandpath")
  pathargs = [
    ('test.py',),
    ('$PATH/test.py',),
    ('foo','bar',),
  ]
  pathkwargs = [
    {'here':True},
    {'here':False},
  ]
  for patharg in pathargs:
    for pathkwarg in pathkwargs:
      LOG.color("storage.expandpath(%s,%s)"%(','.join(repr(a) for a in patharg),','.join("%s=%r"%(k,v) for k,v in pathkwarg.iteritems())))
      result = storage.expandpath(*patharg,**pathkwarg)
      print ">>>   %r"%(result)
  
  # LS
  LOG.header("ls")
  LOG.color("storage.ls(verb=%d)"%(verb))
  storage.ls(verb=verb)
  
  # CP
  LOG.header("cp")
  fname = createdummy("testStorage.txt")
  LOG.color("storage.cp(%r,verb=%d)"%(fname,verb))
  storage.cp(fname,verb=verb)
  storage.ls(verb=verb)
  
  # EXISTS
  LOG.header("exists")
  LOG.color("storage.exists(%r,verb=%d)"%(fname,verb))
  result = storage.exists(fname,verb=verb)
  print ">>>   %r"%(result)
  storage.ls(verb=verb)
  
  # RM
  LOG.header("rm")
  LOG.color("storage.rm(%r,verb=%d)"%(fname,verb))
  storage.rm(fname,verb=verb)
  storage.ls(verb=verb)
  
  # MKDIR
  LOG.header("mkdir")
  dirname = 'test'
  LOG.color("storage.mkdir(%r.verb=%d)"%(dirname,verb))
  storage.mkdir(dirname,verb=verb)
  storage.ls(verb=verb)
  storage.ls(dirname,verb=verb)
  
  # RM DIRECTORY
  LOG.header("rm directory")
  submit = raw_input(">>> Careful! Do you really want to remove %r? [y/n] "%(storage.expandpath(dirname,here=True)))
  if submit=='y':
    LOG.color("storage.rm(%r,verb=%d)"%(dirname,verb))
    storage.rm(dirname,verb=verb)
    storage.ls(verb=verb)
  
  # HADD
  LOG.header("hadd")
  infiles = [createdummyroot("testStorage1.root"),createdummyroot("testStorage2.root")]
  outfile = "testStorage.root"
  for tmpdir in [True,]: #False
    LOG.color("storage.hadd(%r,%r,tmpdir=%s,verb=%d)"%(infiles,outfile,tmpdir,verb))
    storage.hadd(infiles,outfile,tmpdir=tmpdir,verb=verb)
    storage.ls(verb=verb)
    storage.rm(outfile,verb=verb)