Skip to content

Instantly share code, notes, and snippets.

@HugoKuo
Forked from clayg/list_expired.py
Created January 8, 2018 05:21
Show Gist options
  • Save HugoKuo/18899b813e6b67986869959221ed4cf2 to your computer and use it in GitHub Desktop.
Save HugoKuo/18899b813e6b67986869959221ed4cf2 to your computer and use it in GitHub Desktop.
this will list expired objects from the .expiring_objects account in a format that you can feed to swift-integrity do_delete
import sys
import time
import urllib
from swift.common.internal_client import InternalClient
from swift.container.sync import ic_conf_body
from swift.common.wsgi import ConfigString
from swift.common.utils import split_path
def main():
now = time.time()
expiring_account = '.expiring_objects'
swift = InternalClient(ConfigString(ic_conf_body), 'test', 1)
for container_item in swift.iter_containers(expiring_account):
container = container_item['name']
if int(container) > now:
break
for item in swift.iter_objects(expiring_account, container):
obj = item['name']
ts, path = obj.split('-', 1)
if int(ts) > now:
break
a, c, o = split_path('/' + path, 1, 3, True)
print ' '.join((
urllib.quote(a.encode('utf8')),
urllib.quote(c.encode('utf8')),
urllib.quote(o.encode('utf8'))))
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment