#68 Merge releases-json.py functionality into main.py
Opened a year ago by fbaumanis. Modified 11 months ago
fedora-web/ fbaumanis/websites issue_53  into  master

file modified
+58 -1
@@ -5,9 +5,13 @@ 

  from flask_assets import Environment, Bundle

  from flask_frozen import Freezer

  from flask_htmlmin import HTMLMIN

+ import fedfind.release

+ import fedfind.helpers

  import jinja2

  import os

  import yaml

+ import json

+ 

  

  # TODO: Is there a nicer way to represent the data globalvar has?

  import globalvar
@@ -83,6 +87,59 @@ 

  # Only include translations which actually have a translations file

  FEDORA_LANGUAGES = {k: v for k, v in FEDORA_LANGUAGES_FULL.items() if k in os.listdir('translations') or k == FEDORA_LANGUAGE_DEFAULT}

  

+ # some function definitions

+ def get_release_json():

+     r = {}

+     output = []

+ 

+     with open(os.path.join(os.path.dirname(__file__), 'release.yaml')) as data:

+             r = yaml.safe_load(data)

+     releases_to_report = []

+     for release in r.get('fmw', {}).get('releases_json', []):

+         version = release.get('version')

+         if version is None:

+             raise Exception('Malformed yaml section: fmw.releases_json, each entry must at ' + 'least have a "version" field.')

+         milestone = release.get('milestone', 'final')

+         releases_to_report.append(

+                 fedfind.release.get_release(

+                     int(version),

+                     milestone = milestone))

+         for rel in releases_to_report:

+             for img in rel.all_images:

+                 location = img['url']

+                 h = hashify(

+                         rel.version,

+                         rel.milestone,

+                         img['arch'],

+                         location,

+                         img['variant'],

+                         img['subvariant'])

+                 if 'checksums' in img and 'sha256' in img['checksums']:

+                     h['sha256'] = str(img['checksums']['sha256'])

+                 if 'size' in img:

+                     h['size'] = str(img['size'])

+                 output.append(h)

+ 

+     json_out_file = open(os.path.join(os.path.dirname(__file__), 'static', 'releases.json'), 'w+')

+     json.dump(output, json_out_file)

+ 

+ 

+ 

+ 

+     return json.dumps(output)

+ 

+ def hashify(version, milestone, arch, link, variant, subvariant):

+     return { 'version': version,

+              'arch': arch,

+              'link': link,

+              'variant': variant,

+              'subvariant': subvariant}

+ 

+ 

+ 

+ 

+ 

+ 

  # Set this early so we can base routing logic on it.

  if __name__ == '__main__':

      freezing = True
@@ -221,9 +278,9 @@ 

  # python scripts/releases-json.py > static/releases.json

  @app.route('/releases.json')

  def releases_json():

+     get_release_json()

      return send_from_directory('static', 'releases.json')

  

- 

  @app.route('/magazine.json')

  def magazine_json():

      return send_from_directory('static', 'magazine.json')

@@ -1,54 +0,0 @@ 

- #!/usr/bin/env python

- import fedfind.release

- import fedfind.helpers

- import json

- import os

- import yaml

- 

- r = {}

- output = []

- 

- with open(os.path.join(os.path.dirname(__file__), '..', 'release.yaml')) as data:

-     r = yaml.safe_load(data)

- 

- def hashify(version, milestone, arch, link, variant, subvariant):

-     return { 'version': version

-            , 'arch': arch

-            , 'link': link

-            , 'variant': variant

-            , 'subvariant': subvariant

-            }

- 

- releases_to_report = []

- for release in r.get('fmw', {}).get('releases_json', []):

-     version = release.get('version')

-     if version is None:

-         raise Exception(

-             'Malformed yaml section: fmw.releases_json, each entry must at ' +

-             'least have a "version" field.')

-     milestone = release.get('milestone', 'final')

-     releases_to_report.append(

-         fedfind.release.get_release(

-             int(version),

-             milestone=milestone))

- 

- for rel in releases_to_report:

-     for img in rel.all_images:

-         location = img['url']

-         h = hashify(

-                 rel.version,

-                 rel.milestone,

-                 img['arch'],

-                 location,

-                 img['variant'],

-                 img['subvariant'])

- 

-         if 'checksums' in img and 'sha256' in img['checksums']:

-             h['sha256'] = str(img['checksums']['sha256'])

- 

-         if 'size' in img:

-             h['size'] = str(img['size'])

- 

-         output.append(h)

- 

- print (json.dumps(output))

Merge releases-json.py functionality into main.py.

Is this right? release.yaml is in the same dir as main.py right?

Please nuke these extraneous blank lines

2 new commits added

  • Fix automatic creation of releases.json
  • Fix directory for releases.yaml in mian.py
a year ago

Fixed it, should be better now. Thanks for your review points!

Is there any review update?