当前位置: 首页>>代码示例>>Python>>正文


Python GSConnection.get_all_buckets方法代码示例

本文整理汇总了Python中boto.gs.connection.GSConnection.get_all_buckets方法的典型用法代码示例。如果您正苦于以下问题:Python GSConnection.get_all_buckets方法的具体用法?Python GSConnection.get_all_buckets怎么用?Python GSConnection.get_all_buckets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.gs.connection.GSConnection的用法示例。


在下文中一共展示了GSConnection.get_all_buckets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from boto.gs.connection import GSConnection [as 别名]
# 或者: from boto.gs.connection.GSConnection import get_all_buckets [as 别名]
class BackupManager:

    def __init__(self, accesskey, sharedkey):
        self._accesskey = accesskey
        self._connection = GSConnection(accesskey, sharedkey)

        self._buckets = None
        self._bucketbackups = {}
        self._backups = None

    def _generate_backup_buckets(self):
        bucket_prefix = 'bkup-'
        bucket_suffix = '-' + self._accesskey.lower()
        buckets = self._connection.get_all_buckets()
        self._buckets = []

        for bucket in buckets:
            if bucket.name.startswith(bucket_prefix) and bucket.name.endswith(bucket_suffix):
                self._buckets.append(bucket)

    @property
    def backup_buckets(self):   # property
        if self._buckets is None:
            self._generate_backup_buckets()
        return self._buckets

    def _list_backups(self, bucket):
        """Returns a dict of backups in a bucket, with dicts of:
        {hostname (str):
            {Backup number (int):
                {'date': Timestamp of backup (int),
                 'keys': A list of keys comprising the backup,
                 'hostname': Hostname (str),
                 'backupnum': Backup number (int),
                 'finalized': 0, or the timestamp the backup was finalized
                }
            }
        }
        """

        backups = {}

        for key in bucket.list():
            keyparts = key.key.split('.')
            final = False

            if keyparts[-1] == 'COMPLETE':
                final = True
                keyparts.pop() # back to tar
                keyparts.pop() # back to backup number
            else:
                if keyparts[-1] == 'gpg':
                    keyparts.pop()

                if keyparts[-1] != 'tar' and len(keyparts[-1]) is 2:
                    keyparts.pop()

                if keyparts[-1] == 'tar':
                    keyparts.pop()

            nextpart = keyparts.pop()
            if nextpart == 'COMPLETE':
                print("Stray file: %s" % key.key)
                continue
            backupnum = int(nextpart)
            hostname = '.'.join(keyparts)

            lastmod = time.strptime(key.last_modified,
                                    '%Y-%m-%dT%H:%M:%S.%fZ')

            if hostname in backups.keys():
                if not backupnum in backups[hostname].keys():
                    backups[hostname][backupnum] = {
                        'date': lastmod,
                        'hostname': hostname,
                        'backupnum': backupnum,
                        'finalized': 0,
                        'keys': [],
                        'finalkey': None,
                        'finalized_age': -1,
                    }
            else:
                backups[hostname] = {
                    backupnum: {
                        'date': lastmod,
                        'hostname': hostname,
                        'backupnum': backupnum,
                        'finalized': 0,
                        'keys': [],
                        'finalkey': None,
                        'finalized_age': -1,
                    }
                }
            if final:
                backups[hostname][backupnum]['finalized'] = lastmod
                backups[hostname][backupnum]['finalkey'] = key
                timestamp = time.mktime(lastmod)
                delta = int(time.time() - timestamp + time.timezone)
                backups[hostname][backupnum]['finalized_age'] = delta
            else:
#.........这里部分代码省略.........
开发者ID:designsforhealth,项目名称:backuppc-archive-s3,代码行数:103,代码来源:backup-manager.py


注:本文中的boto.gs.connection.GSConnection.get_all_buckets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。