This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Purpose of the script goes here. | |
Example usage for the script goes here. | |
python this_script.py <args> | |
""" | |
import os | |
import sys | |
import urllib2 | |
import wget |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/bash | |
# Create and populate a repository. | |
set -euo pipefail | |
# hammer auth login -u admin -p changeme | |
hammer -u admin -p changeme product create --name repotest --organization-id 1 | |
hammer -u admin -p changeme repository create \ | |
--content-type 'yum' \ | |
--url 'https://repos.fedorapeople.org/pulp/pulp/fixtures/rpm-signed/' \ | |
--download-policy 'on_demand' \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import asyncio | |
import sys | |
try: | |
import bugzilla | |
except ImportError: | |
print('Install dependencies with `pip install -r -requirements.txt`.') | |
sys.exit(-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Simple Config - Config.... Simplified!""" | |
import json | |
import os | |
import yaml | |
from pathlib import Path | |
from logzero import logger | |
class SimpleConfig: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For this, we will be using the python-bugzilla module | |
pip install python-bugzilla | |
This provides 'bugzilla' command, which is the interface we'll be using. | |
bugzilla has a "modify" sub command which allows us to update a bug via the CLI. | |
The most important piece of this is to pass the following argument, which surpresses email updates. | |
--field=minor_update=1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class MyBase: | |
"""This is a base class""" | |
def __init__(self, **kwargs): | |
"""Assign each key, value pair to our class instance""" | |
for arg, val in kwargs.items(): | |
self.__dict__[arg] = val |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generators and iterators | |
import random | |
def my_gen(in_str="This is a sentence."): | |
"""A generator that returns on character in a string per iteration""" | |
for char in in_str: | |
yield char # return one character and wait | |
def big_list(): | |
"""Create a list of number from 0 to 100 million""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Decorators provide a way to intercept a decorated function, method, or class. | |
Ultimately, the decorator accepts the function as its only argument | |
Decorators can then either return the original function, or another one | |
""" | |
def change_name(func): | |
"""This decorator just changes the name of any decorated function""" | |
func.__name__ = "changed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Pytest fixtures | |
Fixtures give you a convenient way to perform setup actions outside of a test. | |
By limiting or expanding the scope of a fixture, you can cut down on costly setup tasks. | |
""" | |
import pytest | |
import random | |
import unittest2 # please never | |
NUM = "0123456789" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aiohttp | |
import asyncio | |
import async_timeout | |
import click | |
from logzero import logger | |
from pathlib import path | |
class AsyncRunner: | |
"""A general class to perform async requests and process data""" |