clone.py 1.53 KB
Newer Older
1 2 3 4 5 6
'''
Created on 28 sept. 2014

@author: coissac
'''

Eric Coissac committed
7
from orgasm import getOutput
8
import shutil
Eric Coissac committed
9 10
import sys
import os
11 12 13 14 15

__title__="copy an assembly"


default_config = { "source" : None,
Eric Coissac committed
16 17
                   "dest"   : None,
                   "force"  : False
18 19 20 21 22 23 24 25 26
                 }

def addOptions(parser):
    parser.add_argument(dest='orgasm:outputfilename',  metavar='outputfilename', 
                        help='name of the assembly to be copied')
    
    parser.add_argument(dest='clone:dest',     metavar='dest', 
                        help='name of the new copy of the assembly' )
    
Eric Coissac committed
27 28 29 30 31
    parser.add_argument("--force","-f",
                        dest='clone:force',
                        action='store_true',
                        default=None,
                        help='Force cloning even if the destination already exist' )
32 33 34 35 36 37 38 39 40 41 42 43
    


def run(config):
    
    logger=config['orgasm']['logger']
    progress = config['orgasm']['progress']

    source = getOutput(config)
    
    logger.info("Copying the assembly %s to %s" % (config['orgasm']['outputfilename'],
                                                   config['clone']['dest'])) 
Eric Coissac committed
44 45 46 47 48 49 50
    
    if os.path.exists("%s.oas"  % config['clone']['dest']):
        if config['clone']['force']:
            shutil.rmtree("%s.oas"  % config['clone']['dest'])
        else:
            logger.error('Destination assembling exists')
            sys.exit(1)
51 52 53 54 55
        
    shutil.copytree("%s.oas"  % config['orgasm']['outputfilename'], 
                    "%s.oas"  % config['clone']['dest'])