Пример #1
0
def write_data_to_file(data, filename, quiet=False):
    """
        Writes the data to the given filename.
        If the data did not change, the file is not touched.

    """
    from mcdp import logger

    if not isinstance(data, str):
        msg = 'Expected "data" to be a string, not %s.' % type(data).__name__
        raise ValueError(msg)

    if len(filename) > 256:
        msg = 'Invalid argument filename: too long. Did you confuse it with data?'
        raise ValueError(msg)

    filename = expand_all(filename)
    make_sure_dir_exists(filename)

    if os.path.exists(filename):
        current = open(filename).read()
        if current == data:
            if not 'assets' in filename:
                if not quiet:
                    logger.debug('already up to date %s' %
                                 friendly_path(filename))
            return

    with open(filename, 'w') as f:
        f.write(data)

    if not quiet:
        size = '%.1fMB' % (len(data) / (1024 * 1024))
        logger.debug('Written %s to: %s' % (size, friendly_path(filename)))
Пример #2
0
def sync_data_down_dir(syncdir):
    
    if not os.path.exists(syncdir):
        os.makedirs(syncdir)
    
    syncdir = os.path.realpath(syncdir)

    if not syncdir or not syncdir[0] == '/':
        msg = 'I expect the multyvac_sync_down dir to be an absolute path,'
        msg += ' got %r.' % syncdir
        raise ValueError(msg)
    
    vol, rest, rest_minus = get_volume_for_dir(syncdir)
    info(down_arrow + ' Synchronizing directory %r down.' % friendly_path(syncdir))
    vol.sync_down(rest, os.path.dirname(syncdir))
Пример #3
0
def sync_data_down_dir(syncdir):

    if not os.path.exists(syncdir):
        os.makedirs(syncdir)

    syncdir = os.path.realpath(syncdir)

    if not syncdir or not syncdir[0] == '/':
        msg = 'I expect the multyvac_sync_down dir to be an absolute path,'
        msg += ' got %r.' % syncdir
        raise ValueError(msg)

    vol, rest, rest_minus = get_volume_for_dir(syncdir)
    info(down_arrow +
         ' Synchronizing directory %r down.' % friendly_path(syncdir))
    vol.sync_down(rest, os.path.dirname(syncdir))
Пример #4
0
def sync_data_up_dir(syncdir, skipsync=False):
    if not os.path.exists(syncdir):
        msg = 'Dir %r does not exist.' % syncdir
        raise ValueError(msg)
    
    syncdir = os.path.realpath(syncdir)

    if not syncdir or not syncdir[0] == '/':
        msg = 'I expect the multyvac_sync_up dir to be an absolute path,'
        msg += ' got %r.' % syncdir
        raise ValueError(msg)
    
    vol, rest, rest_minus = get_volume_for_dir(syncdir)
    
    vol.mkdir(rest)
    if not skipsync:
        info(up_arrow + ' Synchronizing directory %r up.' % friendly_path(syncdir))
        vol.sync_up(syncdir, rest_minus)
    
    return vol.name
Пример #5
0
def sync_data_up_dir(syncdir, skipsync=False):
    if not os.path.exists(syncdir):
        msg = 'Dir %r does not exist.' % syncdir
        raise ValueError(msg)

    syncdir = os.path.realpath(syncdir)

    if not syncdir or not syncdir[0] == '/':
        msg = 'I expect the multyvac_sync_up dir to be an absolute path,'
        msg += ' got %r.' % syncdir
        raise ValueError(msg)

    vol, rest, rest_minus = get_volume_for_dir(syncdir)

    vol.mkdir(rest)
    if not skipsync:
        info(up_arrow +
             ' Synchronizing directory %r up.' % friendly_path(syncdir))
        vol.sync_up(syncdir, rest_minus)

    return vol.name