예제 #1
0
def copy_to_dest(f,dirn):
    """Copy a file to a local or remote destination

    Raises an exception if the copy operation fails.

    Arguments:
      f: file to copy (must be local)
      dirn: target directory, either local or of the form
        "[user@]host:dir"
    
    """
    if not os.path.exists(f):
        raise Exception("File %s doesn't exist" % f)
    user,host,dest = utils.split_user_host_dir(dirn)
    remote = (host is not None)
    if not remote:
        # Local copy
        shutil.copy(f,dirn)
    else:
        # Remote copy
        try:
            scp = applications.general.scp(user,host,f,dest)
            print "Running %s" % scp
            scp.run_subprocess()
        except Exception, ex:
            raise Exception("Failed to copy %s to %s: %s" % (f,dirn,ex))
def copy_to_dest(f, dirn, chksum=None, link=False):
    """Copy a file to a local or remote destination

    Raises an exception if the copy operation fails.

    If 'chksum' argument is supplied then the MD5 sum of
    the copy is also verified against this and an
    exception is raised if this fails to match.

    Arguments:
      f: file to copy (must be local)
      dirn: target directory, either local or of the form
        "[user@]host:dir"
      chksum: (optional) MD5 sum of the original file
        to match against the copy
      link: (optional) if True then hard link files
        instead of copying
    
    """
    if not exists(f):
        raise Exception("'%s': not found" % f)
    if not exists(dirn):
        raise Exception("'%s': destination not found" % dirn)
    # Copy the file
    copy(f, dirn, link=link)
    if chksum is not None:
        user, host, dest = utils.split_user_host_dir(dirn)
        remote = (host is not None)
        if not remote:
            # Check local copy
            if chksum is not None:
                if md5sum.md5sum(f) != chksum:
                    raise Exception("MD5 checksum failed for "
                                    "copy of %s" % f)
        else:
            # Check remote copy
            try:
                # Run md5sum -c on the remote system
                if chksum is not None:
                    md5sum_check = applications.general.ssh_command(
                        user, host,
                        ('echo', '"%s  %s"' %
                         (chksum, os.path.join(dest, os.path.basename(f))),
                         '|', 'md5sum', '-c'))
                    print("Running %s" % md5sum_check)
                    md5sum_check.run_subprocess()
            except Exception as ex:
                raise Exception("Failed to copy %s to %s: %s" % (f, dirn, ex))
def copy_to_dest(f,dirn,chksum=None):
    """Copy a file to a local or remote destination

    Raises an exception if the copy operation fails.

    If 'chksum' argument is supplied then the MD5 sum of
    the copy is also verified against this and an
    exception is raised if this fails to match.

    Arguments:
      f: file to copy (must be local)
      dirn: target directory, either local or of the form
        "[user@]host:dir"
      chksum: (optional) MD5 sum of the original file
        to match against the copy
    
    """
    if not os.path.exists(f):
        raise Exception("File %s doesn't exist" % f)
    user,host,dest = utils.split_user_host_dir(dirn)
    remote = (host is not None)
    if not remote:
        # Local copy
        shutil.copy(f,dirn)
        if chksum is not None:
            if md5sum.md5sum(f) != chksum:
                raise Exception("MD5 checksum failed for copy of %s" % f)
    else:
        # Remote copy
        try:
            scp = applications.general.scp(user,host,f,dest)
            print "Running %s" % scp
            scp.run_subprocess()
            # Run md5sum -c on the remote system
            if chksum is not None:
                md5sum_check = applications.general.ssh_command(
                    user,host,
                    ('echo',
                     '"%s  %s"' % (chksum,
                                   os.path.join(dest,os.path.basename(f))),
                    '|','md5sum','-c'))
                print "Running %s" % md5sum_check
                md5sum_check.run_subprocess()
        except Exception, ex:
            raise Exception("Failed to copy %s to %s: %s" % (f,dirn,ex))
예제 #4
0
def copy_to_dest(f, dirn, chksum=None):
    """Copy a file to a local or remote destination

    Raises an exception if the copy operation fails.

    If 'chksum' argument is supplied then the MD5 sum of
    the copy is also verified against this and an
    exception is raised if this fails to match.

    Arguments:
      f: file to copy (must be local)
      dirn: target directory, either local or of the form
        "[user@]host:dir"
      chksum: (optional) MD5 sum of the original file
        to match against the copy
    
    """
    if not os.path.exists(f):
        raise Exception("File %s doesn't exist" % f)
    user, host, dest = utils.split_user_host_dir(dirn)
    remote = (host is not None)
    if not remote:
        # Local copy
        shutil.copy(f, dirn)
        if chksum is not None:
            if md5sum.md5sum(f) != chksum:
                raise Exception("MD5 checksum failed for copy of %s" % f)
    else:
        # Remote copy
        try:
            scp = applications.general.scp(user, host, f, dest)
            print "Running %s" % scp
            scp.run_subprocess()
            # Run md5sum -c on the remote system
            if chksum is not None:
                md5sum_check = applications.general.ssh_command(
                    user, host,
                    ('echo', '"%s  %s"' %
                     (chksum, os.path.join(dest, os.path.basename(f))), '|',
                     'md5sum', '-c'))
                print "Running %s" % md5sum_check
                md5sum_check.run_subprocess()
        except Exception, ex:
            raise Exception("Failed to copy %s to %s: %s" % (f, dirn, ex))
예제 #5
0
         print "Project_name\t#smpl\tQC?\tFq_are_lns\tSample_names"
         for project in analysis_dir.projects:
             fq_target = fastqs_are_linked(project)
             line = [project.name,
                     len(project.samples),
                     ('ok' if project.verify_qc() else '?'),
                     ('yes' if fq_target is not None else 'no'),
                     project.prettyPrintSamples()]
             print "%s" % '\t'.join([str(x) for x in line])
         print ""
 elif cmd == 'copy':
     # Copy fastqs
     if len(args) != 2:
         p.error("Need to supply a destination directory")
     # Check destination
     user,host,dest_dir = utils.split_user_host_dir(args[1])
     if host is None:
         dest_dir = os.path.abspath(dest_dir)
         print "Copying to local directory: %s" % dest_dir
     else:
         dest_dir = args[1]
         print "Copying to remote directory: %s" % dest_dir
     # Fetch fastqs
     if options.projects is None:
         project_pattern = '*'
         sample_pattern = '*'
     else:
         project_pattern = options.projects.split('/')[0]
         try:
             sample_pattern = options.projects.split('/')[1]
         except IndexError: