Ejemplo n.º 1
0
def secure_copy(presetdata):
    ''' Uses the presetdata to copy the file to the remote destination
        -v -P4900 -o StrictHostKeyChecking=no -o BatchMode=yes'''
    source_file = presetdata['source_file']
    basename = shutil.os.path.split(source_file)[1]
    if 'rename_to' in presetdata:
        rename_to = presetdata['rename_to']
        if rename_to != '':
            basename = shutil.os.path.split_ext(basename) + rename_to
    dest_file = shutil.os.path.join(presetdata['destination_dir'],basename)   
    options = ''
    for opt in presetdata['option']:
        options = '{} -o "{}"'.format(options,opt) 

    command = 'scp -v -i {idfile} -P {port} {options} {localfile} {user}@{server}:{destination}'.format(
            idfile = presetdata['idfile'],
            user = presetdata['username'],
            server = presetdata['server'],
            localfile = presetdata['source_file'],
            destination = presetdata['destination_dir'],
            port = presetdata['port'],
            options = '' #options
    )
    log (command, 8)
    result, error, code = run_cmd(command)
Ejemplo n.º 2
0
def load_preset(presetName, data):
    filename = shutil.os.path.join(data['presetpath'],presetName + '.json')
    preset = Info(filename)
    if not shutil.os.path.isfile(filename):
        preset.name = presetName
    preset.load(create=True)
    if not 'init' in preset.data:
        preset.data = fill_data(preset.data)
    log('Loaded preset: {}'.format(presetName),10)
    return preset
Ejemplo n.º 3
0
def fill_data(pres_data):
    def get_var():
        newval = input(q)
        if newval == '*':
            newval = manage_defaults(var)
        return newval

    print ('Enter new values: {} lets you pick or enter defaults'.format("'*'"))
    new_data = [['source_file','Enter path of sourcefile','string'],
                ['destination_dir','Enter destination directory','string'],
                ['server','Enter destination server','string'],
                ['username','Enter username','string'],
                ['rename_to','Rename to extension. Leave empty to use original','string'],
                ['idfile','ssh_id_file','string'],
                ['port','The port to connect on','string'],
                ['option','The options','list'],
                ['init','Change this file next time. Type "y" if Finished','boolean']
    ]   
    for var, question, d_type in new_data:
        if var in pres_data:
            if pres_data[var].__class__ == list:
                varval = ', '.join(pres_data[var])
            else:
                varval = pres_data[var]
            q = ' :: {varname:20} :: {var:50}  ::\n{q}:'.format(q=question,var=varval,varname=var)
        else:
            q = question + ': '
        newval = get_var()
        if d_type == 'string':
            if newval != '':
                pres_data[var] = newval
                print ('Using: {}'.format(newval)) 
        elif d_type == 'list':
            if not var in pres_data:
                pres_data[var] = [newval]
            while newval != '': 
                if not newval in pres_data[var]:
                    pres_data[var].append(newval)
                newval = get_var()
        elif d_type == 'boolean':
            if newval in 'yesYESjaoui1':
               pres_data[var] = True
            elif newval in 'Nn0':
               pres_data[var] = False 
        else:
            log('Not implemented (or typo): {}'.format(d_type))

    #pres_data['init'] = 'done'
    return pres_data
Ejemplo n.º 4
0
def check_sync(presetdata):
    ''' checks if the mtime of the file is different than recorded
        Returns True if file is in sync, 
        false if newer or there are no records yet'''

    current_mtime = check_age(presetdata['source_file'])
    log("The age of the file is {}".format(current_mtime), 10)
    if not 'last_mtime' in presetdata:
       presetdata['last_mtime'] = current_mtime
       return False
    if presetdata['last_mtime'] != current_mtime:
        if not 'sync_history' in presetdata:
           presetdata['sync_history'] = []
        presetdata['sync_history'].append(presetdata['last_mtime'])
        presetdata['last_mtime'] = current_mtime
        return False
    
    return True
Ejemplo n.º 5
0
        options = '{} -o "{}"'.format(options,opt) 

    command = 'scp -v -i {idfile} -P {port} {options} {localfile} {user}@{server}:{destination}'.format(
            idfile = presetdata['idfile'],
            user = presetdata['username'],
            server = presetdata['server'],
            localfile = presetdata['source_file'],
            destination = presetdata['destination_dir'],
            port = presetdata['port'],
            options = '' #options
    )
    log (command, 8)
    result, error, code = run_cmd(command)
<<<<<<< HEAD
<<<<<<< HEAD
    log('Command ended with success {}'.format('-'), 10)
    if code != 0:
        log('Command ended with error {} {}'.format(result, error), 6)

log_init(loglevel, logdir, logfile)
log('Starting autoscp script. Logging set to {}'.format(loglevel),8)
=======
    log('Command ended with success {}'.format(result), 10)
=======
    log('Command ended with success {}'.format('-'), 10)
>>>>>>> afd8837... fix spacewlk
    if code != 0:
        log('Command ended with error {} {}'.format(result, error), 6)

log_init(loglevel, logdir, logfile)
<<<<<<< HEAD