From a0046607add9cd2b4695e826d2cfcecd2b7c2fcb Mon Sep 17 00:00:00 2001 From: Tim Flink Date: Nov 01 2017 16:12:21 +0000 Subject: [PATCH 1/2] adding pyo and vim swap files to gitignore --- diff --git a/.gitignore b/.gitignore index f9e96cd..e4f16da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ __pycache__/ #* -*.pyc \ No newline at end of file +*.py[co] +.*.swp From 8fa662c3f292d491ccd8a4f8cad841eb3ba78bd1 Mon Sep 17 00:00:00 2001 From: Tim Flink Date: Nov 01 2017 16:19:37 +0000 Subject: [PATCH 2/2] adding tox.ini for flake8 settings, style updates for python code --- diff --git a/api_server.py b/api_server.py index 5781439..5b3c4d7 100644 --- a/api_server.py +++ b/api_server.py @@ -5,7 +5,7 @@ # Author: Mike Ruckman import hug -from sqlalchemy import create_engine, func +from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from marshmallow_sqlalchemy import ModelSchema @@ -18,13 +18,16 @@ Session.configure(bind=engine) session = Session() + class ProjectSchema(ModelSchema): '''Make it so we can serialize our objects to json.''' class Meta: model = Project + schema = ProjectSchema() + @hug.directive() def cors(support="*", response=None, **kwargs): '''Set the 'Access-Control-Allow-Origin' header for all requests, @@ -32,21 +35,25 @@ def cors(support="*", response=None, **kwargs): ''' response and response.set_header('Access-Control-Allow-Origin', '*') + @hug.get(accept=('GET', 'OPTIONS')) def all(hug_cors): '''Return a list of all projects in the database.''' return [schema.dump(x).data for x in session.query(Project).all()] + @hug.get() def migrated(hug_cors): '''Return a list of all migrated projects.''' migrated = [schema.dump(x).data for x in session.query(Project).filter_by(status=u'MIGRATED').all()] + @hug.get() def working(hug_cors): '''Return a list of all working projects.''' return [schema.dump(x).data for x in session.query(Project).filter_by(status=u'WORKING').all()] + @hug.get() def counts(hug_cors): '''Return the counts of each status.''' diff --git a/server.py b/server.py index 641e4cd..c66d088 100644 --- a/server.py +++ b/server.py @@ -19,6 +19,7 @@ from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() + class Project(Base): __tablename__ = 'projects' @@ -28,19 +29,19 @@ class Project(Base): status = Column(String) pagure_link = Column(String) contact = Column(String) - + def get_project_issues(self): '''Update self.status to WORKING if there are issues attached to it.''' issues_url = config.API_URL + "{}/issues".format(self.name) issues = requests.get(issues_url) - + if issues.status_code == 404: logging.debug("Issues not found for: {}".format(self.name)) return None - + issues = json.loads(issues.text) - + if issues['total_issues'] is not 0: self.update_status("WORKING") else: @@ -49,6 +50,7 @@ class Project(Base): def update_status(self, status): self.status = status + def get_session(): '''Return a session object to interact with the database.''' @@ -56,19 +58,20 @@ def get_session(): Session.configure(bind=engine) return Session() - + + def setup_database(): '''Do the initial setup of the database. This should be run once.''' Base.metadata.create_all(engine) session = get_session() - + logging.info("Reading in the package list...\n") with open('UpstreamFirstPackageList.csv', 'r') as rawlist: packages = rawlist.readlines() # Remove the header row packages = packages[1:] - + logging.info("There are {} packages initially\n".format(len(packages))) for package in clean_list(packages): package = hawkey.split_nevra(package) @@ -77,17 +80,19 @@ def setup_database(): session.commit() session.close() - + + def clean_list(package_list): '''Clean out the packages that won't be getting tests for Fedora.''' clean = [] for package in package_list: pname, comment = package.split(',') - + if "N/A" not in comment: clean.append(pname) return clean + def parse_fork(project): '''Split out the information from a fork so we can update the status of the correct project. @@ -96,6 +101,7 @@ def parse_fork(project): return project.split('/')[2] + def update_project(project=None, poc=None, session=None): '''Query the database for an existing entry, if it exists, update it. If it doesn't exist, ignore it (since the database is pre-seeded with @@ -117,18 +123,19 @@ def update_project(project=None, poc=None, session=None): proj.update_status(u"MIGRATED") else: pass - + session.add(proj) session.commit() session.close() + def main(): '''Pull the data from the remote source, compare all items to what we have in the database and update anything that needs updated. ''' session = get_session() - + upstream_tests = requests.get(config.API_URL + "projects") upstream_tests = json.loads(upstream_tests.text)['projects'] @@ -149,13 +156,13 @@ def main(): session.commit() session.close() - + if __name__ == '__main__': parser = argparse.ArgumentParser(description='Script to update the local uf-monitor database.') parser.add_argument('--create', help='Initialize the database', action='store_true') - + engine = create_engine(config.DATASTORE, echo=False) args = parser.parse_args() diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..05f2c97 --- /dev/null +++ b/tox.ini @@ -0,0 +1,17 @@ +# This is a common file where different test suites/linters can be configured. + +[flake8] +# If you want to ignore a specific source code line, use '# noqa' comment. If +# you want to ignore the whole file, add '# flake8: noqa' comment. Read more +# documentation about flake8 at: +# https://flake8.readthedocs.org/ +max-line-length=99 + +[pep8] +max-line-length=99 + +[pytest] +minversion=2.0 +python_functions=test should +python_files=test_* functest_* +addopts=--functional testing/ --cov-report=term-missing --cov libtaskotron