#5 some cleanup
Merged 6 years ago by roshi. Opened 6 years ago by tflink.
fedora-qa/ tflink/uf-monitor feature/cleanup-and-sanity  into  master

file modified
+2 -1
@@ -1,4 +1,5 @@ 

  *~

  __pycache__/

  #*

- *.pyc 

\ No newline at end of file

+ *.py[co]

+ .*.swp

file modified
+8 -1
@@ -5,7 +5,7 @@ 

  # Author: Mike Ruckman <roshi@fedoraproject.org>

  

  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 = 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 @@ 

      '''

      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.'''

file modified
+20 -13
@@ -19,6 +19,7 @@ 

  

  Base = declarative_base()

  

+ 

  class Project(Base):

  

      __tablename__ = 'projects'
@@ -28,19 +29,19 @@ 

      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 @@ 

      def update_status(self, status):

          self.status = status

  

+ 

  def get_session():

      '''Return a session object to interact with the database.'''

  
@@ -56,19 +58,20 @@ 

      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)
@@ -80,17 +83,19 @@ 

  

      # Now run the main() method to update with info from the forge.

      main()

-     

+ 

+ 

  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.
@@ -99,6 +104,7 @@ 

  

      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
@@ -120,18 +126,19 @@ 

              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']

  
@@ -152,13 +159,13 @@ 

  

      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()

file added
+17
@@ -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

adding config for flake8, updating .gitignore to include .pyo and vim swap files, slight style changes

Pull-Request has been merged by roshi

6 years ago