Skip to content

Instantly share code, notes, and snippets.

View mhrivnak's full-sized avatar

Michael Hrivnak mhrivnak

View GitHub Profile
def bar1():
for x in range(4):
if x == 0:
pass
else:
# coverage thinks this line isn't covered
continue
def bar2():
for x in range(4):
class ConsumerBindCommand(PulpCliCommand):
"""
Base class that binds a consumer to a repository and an arbitrary
distributor.
"""
def __init__(self, context, name=None, description=None, distributor_id=None):
name = name or 'bind'
description = description or _('binds a consumer to a repository')
super(self.__class__, self).__init__(name, description, self.run)
@mhrivnak
mhrivnak / gist:4980483
Created February 18, 2013 20:37 — forked from jdob/gist:4980468
def sync_repo(self, repo, sync_conduit, config):
metadata = _fetch_repo_metadata(repo, config)
new_units = _resolve_units_to_download(metadata, sync_conduit)
def _fetch_repo_metadata(repo, config):
"""
Retrieves the listing of Puppet modules at the configured 'feed' location.
:return: list of modules in the external repository
# -*- coding: utf-8 -*-
# Migration script for existing rpm units to include repodata
#
# Copyright © 2010-2012 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
ENCODING_LIST = ('utf8', 'iso-8859-1', 'cp1252')
def string_to_unicode(data, destructive=False):
"""
Make a best effort to decode a string, trying encodings in a sensible order
based on unscientific expectations of each one's probability of use.
:param data: string to decode
:type data: str
:param destructive: iff True, if all else fails, decodes as utf8 and omits
#!/usr/bin/env python
import eventlet
from eventlet.green import urllib2
def fetch(url):
body = urllib2.urlopen(url).read()
pool = eventlet.GreenPool(15)
with open('files.txt') as f:
#!/usr/bin/env python
from pulp.common.download.config import DownloaderConfig
from pulp.common.download.request import DownloadRequest
from pulp.common.download.backends.curl import HTTPCurlDownloadBackend
with open('files.txt') as f:
requests = [DownloadRequest(url, url.rsplit('/', 1)[1]) for url in f.readlines()]
config = DownloaderConfig('http', max_concurrent=7)
#!/usr/bin/env python
version_elements = [
'1',
'12',
'1a',
'12abc3d4ef',
]
def foo(x, y):
import itertools
def paginate(iterable, page_size):
i = 0
while True:
page = list(itertools.islice(iterable, i, i+page_size))
if not page:
return
i = i + page_size
yield page
#!/usr/bin/env python
import logging
from pulp.common.download.config import DownloaderConfig
from pulp.common.download.request import DownloadRequest
from pulp.common.download.downloaders.event import HTTPEventletDownloader
logging.basicConfig()