from db import PiWheelsDatabase from tools import list_pypi_packages, get_package_info, get_package_versions from piwheels import PiWheelsBuilder from gpiozero import PingServer import pytest db = PiWheelsDatabase() # Test checking build status assert db.build_active() db.deactivate_build() assert not db.build_active() db.activate_build() assert db.build_active() # Test adding a package to the database build_queue = db.build_queue_generator() assert db.get_build_queue() == [] with pytest.raises(StopIteration): next(build_queue) db.add_new_package('abc') assert db.get_total_number_of_packages() == 1 assert db.get_build_queue() == [] assert db.get_package_versions('abc') == [] # Test adding a package version to the database db.add_new_package_version('abc', '0.0.1') assert db.get_total_number_of_package_versions() == 1 assert db.get_build_queue() == [['abc', '0.0.1']] build_queue = db.build_queue_generator()
from logzero import logger, logfile from db import PiWheelsDatabase logfile('/var/log/piwheels-twitter/years_saved.log', maxBytes=1e6) logger.info('START') try: from twitter import twitter except Exception as e: logger.error('{}: {}'.format(e.__class__.__name__, e)) exit() db = PiWheelsDatabase() def get_years_saved(): with open('/home/piwheels/time_saved.txt', 'r') as f: return int(f.readline()) def update_years_saved(time_saved): with open('/home/piwheels/time_saved.txt', 'w') as f: f.write('{}'.format(time_saved)) def roundup(n): years = 25 return ((n // years) + 1) * years years_saved_prev = get_years_saved()
from glob import glob import os import better_exceptions from db import PiWheelsDatabase from auth import dbname, user, host, password db = PiWheelsDatabase(dbname, user, host, password) temp_dir = '/tmp/piwheels' web_dir = '/var/www/html' wheels = glob('{}/*'.format(temp_dir)) for wheel in wheels: wheel_filename = wheel.split('/')[-1] if db.wheel_is_processed(wheel_filename): print('Syncing {}'.format(wheel_filename)) package = '-'.join(wheel_filename.split('-')[:-4]) web_wheel_dir = '{}/{}'.format(web_dir, package) if not os.path.exists(web_wheel_dir): os.makedirs(web_wheel_dir) final_wheel_path = '{}/{}/{}'.format( web_dir, package, wheel_filename ) os.rename(wheel, final_wheel_path) else: print('Skipping {}'.format(wheel_filename))
from math import floor from db import PiWheelsDatabase from tools import bash_dush, bash_dfh db = PiWheelsDatabase() total_packages = db.get_total_packages() total_packages_processed = db.get_total_packages_processed() total_package_versions = db.get_total_package_versions() total_package_versions_processed = db.get_total_package_versions_processed() successful_builds = db.get_total_successful_builds() failed_builds = total_package_versions_processed - successful_builds last_package = db.get_last_package_processed() total_build_time = db.get_total_build_time() data = { 'total_packages': total_packages, 'total_packages_processed': total_packages_processed, 'packages_processed_pc': floor(total_packages_processed / total_packages * 100), 'total_package_versions': total_package_versions, 'total_package_versions_processed': total_package_versions_processed, 'package_versions_processed_pc': floor(total_package_versions_processed / total_package_versions * 100), 'successful_builds': successful_builds,
import pip import os from glob import glob from time import time from db import PiWheelsDatabase from tools import PiWheelsHandler db = PiWheelsDatabase() wc = pip.commands.WheelCommand() handler = PiWheelsHandler() pip.logger.addHandler(handler) class PiWheelsBuilder: """ PiWheels builder class Builds Python wheels of a given version of a given package """ def __init__(self, package, version): self.package = package self.version = version self.filename = None self.filesize = None self.package_version_tag = None self.py_version_tag = None self.abi_tag = None self.platform_tag = None handler.reset()
import io import statistics from logzero import logger, logfile import matplotlib.pyplot as plt from db import PiWheelsDatabase, get_last_month_period plt.rcParams["figure.figsize"] = (10, 6) logfile('/var/log/piwheels-twitter/monthly.log', maxBytes=1e6) db = PiWheelsDatabase() try: from twitter import twitter except Exception as e: logger.error('{}: {}'.format(e.__class__.__name__, e)) exit() def make_month_downloads_graph(): logger.info('Making graph') downloads_last_month = db.get_downloads_in_last_month() days = [d[0] for d in downloads_last_month] downloads = [d[1] for d in downloads_last_month] fig, ax = plt.subplots() plt.bar(range(len(days)), downloads) plt.title('Downloads in {}'.format(month)) plt.xticks(range(len(days)), days)
from db import PiWheelsDatabase from time import sleep db = PiWheelsDatabase() while True: db.update_package_list() db.update_package_version_list() sleep(60)
from datetime import datetime year = datetime.now().year DATA_FILE = '/home/piwheels/time_saved_{}.txt'.format(year) logfile('/var/log/piwheels-twitter/years_saved_this_year.log', maxBytes=1e6) logger.info('START') try: from twitter import twitter except Exception as e: logger.error('{}: {}'.format(e.__class__.__name__, e)) exit() db = PiWheelsDatabase() def get_years_saved(): try: with open(DATA_FILE, 'r') as f: return int(f.readline()) except FileNotFoundError: logger.error('File Not found - setting years saved to 0') update_years_saved(0) return 0 def update_years_saved(time_saved): with open(DATA_FILE, 'w') as f: f.write('{}'.format(time_saved)) def roundup(n):
from piwheels import PiWheelsBuilder from db import PiWheelsDatabase from time import sleep db = PiWheelsDatabase() while True: for package, version in db.build_queue_generator(): if db.build_active(): builder = PiWheelsBuilder(package, version) builder.build_wheel('/home/piwheels/www') builder.log_build() else: print("The build is currently inactive") break sleep(60)
from logzero import logger, logfile from db import PiWheelsDatabase import math logfile('/var/log/piwheels-twitter/millions.log', maxBytes=1e6) logger.info('START') try: from twitter import twitter except Exception as e: logger.error('{}: {}'.format(e.__class__.__name__, e)) exit() db = PiWheelsDatabase() def get_downloads_last_count(): with open('/home/piwheels/downloads.txt', 'r') as f: return int(f.readline()) def update_downloads_last_count(downloads): with open('/home/piwheels/downloads.txt', 'w') as f: f.write('{}'.format(downloads)) def roundup(n): million = 1e6 return int(math.ceil(n / million) * million)
from db import PiWheelsDatabase from auth import dbname, user, host, password db = PiWheelsDatabase(dbname, user, host, password) db.activate_build()
import io import statistics from logzero import logger, logfile import matplotlib.pyplot as plt from db import PiWheelsDatabase logfile('/var/log/piwheels-twitter/daily.log', maxBytes=1e6) db = PiWheelsDatabase() def get_record(record_file): with open(record_file) as f: return int(f.read().strip()) def update_record(record_file, data): with open(record_file, 'w') as f: f.write(str(data)) def make_week_downloads_graph(): logger.info('Making graph') downloads_last_week = db.get_downloads_in_last_week() days = [d[0] for d in downloads_last_week] downloads = [d[1] for d in downloads_last_week] fig, ax = plt.subplots() plt.bar(range(7), downloads) plt.title('Downloads in the last 7 days')
from logzero import logger, logfile from db import PiWheelsDatabase import math logfile('/var/log/piwheels-twitter/thirtydayrecord.log', maxBytes=1e6) logger.info('START') try: from twitter import twitter except Exception as e: logger.error('{}: {}'.format(e.__class__.__name__, e)) exit() db = PiWheelsDatabase() def get_last_milestone(): with open('/home/piwheels/downloads30.txt', 'r') as f: return int(f.readline()) def update_downloads_last_count(downloads): with open('/home/piwheels/downloads30.txt', 'w') as f: f.write('{}'.format(downloads)) def roundup(n): hund_thou = 1e5 return int(math.ceil(n / hund_thou) * hund_thou)