Exemplo n.º 1
0
def view_object():
    path = request.query.path
    cnx = get_session()
    container = get_container()
    log.debug('path: %s' % path)
    object_data = cnx.get_object(container, urllib.unquote(path))
    response.content_type = object_data[0]['content-type']
    response.content_length = object_data[0]['content-length']
    response.content_disposition = 'Content-Disposition: attachment; filename="%s"' % urllib.unquote(path)
    return object_data[1]
Exemplo n.º 2
0
def index():
    global htdocs, templates

    account_info = ''

    try:
        sess = get_session()
        if not app_container_exists(sess):
            create_container(sess)
    except ClientException, e:
        log.error('Swift get_session() error: %s' % e.message, exc_info=True, culprit=__culprit__)
Exemplo n.º 3
0
def browse():
    global htdocs, templates

    cnx = get_session()
    container_info = cnx.get_container(get_container())
    restartneeded = get_reg_value('HKLM', APP_REG_KEY, 'restartneeded')
    internal_error = get_reg_value('HKLM', APP_REG_KEY, 'internal_error', False)
    file_data = {
        'template_lookup': [templates,],
        'restartneeded': restartneeded,
        'internalerror': internal_error,
        'dirs': []
    }
    for files in container_info[1]:
        file_data['dirs'].append(
            {
                'path': files['name'],
                'path_encoded': quote(files['name'], safe='').lstrip('/'),
                'changed': files['last_modified'],
                'size': files['bytes']
            }
        )
        continue
    return file_data
Exemplo n.º 4
0
def sync_dir(dir, sess=None):
    """ Sync the given directory to Dropbox

    """

    start = datetime.datetime.now()
    backup_data = {}
    uploaded_file_list = []
    deleted_file_list = []
    try:
        if not sess:
            sess = get_session()
        log.info('got session')
        container = get_container()
        hash_path = HASHES + dir[3:].replace("\\", '_')
        log.info('created hash_path')
        try:
            log.info('getting hash from %s' % hash_path)
            manifest = json.loads(sess.get_object(container, hash_path)[1])
            log.info('retrieved manifest')
        except ClientException, e:
            log.warning('Error getting manifest:\n   Status: %d\n   Message: %s'
                        % (e.http_status, e.message), culprit=__culprit__)
            if e.http_status == 404:
                # The manifest didn't exist on swift.  This means we need to seed
                # the directory.  We can do so by starting with an empty manifest
                log.evtlog.info('Swift: manifest doesn\'t exist.  Create a blank one')
                manifest = {}
            elif e.http_status == 400:
                log.error('Error loading manifest for %s\nError message:\n\n%s'
                          % (dir, e.message), culprit=__culprit__)
                return
        files_changed = False
        visited_files = []
        for root, dirs, files in os.walk(dir):
            for f in files:
                absolute_path = os.path.join(root, f)
                dbox_absolute_path = dbox_munge_path(absolute_path)
                visited_files.append(absolute_path)
                file_info = manifest.get(absolute_path, None)
                file_stats = get_file_stats(absolute_path)
                if (not file_info) or\
                   (file_info['filesize'] <> file_stats['filesize'] or\
                    file_info['filemtime'] <> file_stats['filemtime'] or\
                    file_info['filehash'] <> file_stats['filehash']):
                    # File is either new or has been updated.  Either way, we
                    # need to upload the file to dropbox and update the manifest
                    manifest[absolute_path] = file_stats
                    uploaded_file_list.append(absolute_path)
                    sess.put_object(container, dbox_absolute_path, open(absolute_path, 'rb'))
                    files_changed = True
                continue
            continue
        backup_data['uploaded_files'] = '\n' + '\n'.join(uploaded_file_list)
        deleted_files = set(manifest.keys()).difference(set(visited_files))
        for f in deleted_files:
            sess.delete_object(container, dbox_munge_path(f))
            files_changed = True
            del manifest[f]
            deleted_file_list.append(absolute_path)
            continue
        backup_data['deleted_files'] = '\n' + '\n'.join(deleted_file_list)
        if files_changed:
            sess.put_object(container, hash_path, json.dumps(manifest))
        set_directory_change_time(dir)
        end = datetime.datetime.now()
        backup_data['duration'] = str(end - start)
        backup_data['start'] = start.strftime('%H:%M:%S')
        backup_data['end'] = end.strftime('%H:%M:%S')
        if files_changed:
            log.sentry.info('Backup complete', culprit=__culprit__, extra=backup_data)