ソースを参照

feat: add links for reporting issues upstream

Nicholas Browning 1 年間 前
コミット
bc14830c63
5 ファイル変更52 行追加22 行削除
  1. 5 3
      lib/combine.py
  2. 23 2
      lib/download.py
  3. 6 4
      lib/list.py
  4. 13 13
      sources.csv
  5. 5 0
      sources/.gitignore

+ 5 - 3
lib/combine.py

@@ -40,9 +40,11 @@ def normalize_string(original, lowercase = True):
 
 for x in templates:
     normalized_title = normalize_string(x['title'])
-    if normalized_title not in seen_titles:
-        seen_titles.add(normalized_title)
-        filtered_data.append(x)
+    if normalized_title in seen_titles:
+        continue
+
+    seen_titles.add(normalized_title)
+    filtered_data.append(x)
 
     categories = x.get('categories', [])
     x['categories'] = []

+ 23 - 2
lib/download.py

@@ -1,6 +1,7 @@
 import os
 import csv
 import requests
+import json
 
 dir = os.path.dirname(os.path.abspath(__file__))
 
@@ -8,8 +9,9 @@ destination_dir = os.path.join(dir, '../sources')
 sources_list = os.path.join(dir, '../sources.csv')
 
 # Downloads the file from a given URL, to the local destination
-def download(url: str, filename: str):
+def download(url: str, filename: str, maintainer: str):
     file_path = os.path.join(destination_dir, filename)
+    print('Downloading', url)
     r = requests.get(url, stream=True)
     if r.ok:
         print('saving to', os.path.abspath(file_path))
@@ -19,6 +21,25 @@ def download(url: str, filename: str):
                     f.write(chunk)
                     f.flush()
                     os.fsync(f.fileno())
+
+        sourceJson = {}
+        with open(file_path) as f:
+            try:
+                sourceJson = json.load(f)
+                # Add maintainer field to each template
+                for t in sourceJson.get('templates', []):
+                    t['maintainer'] = maintainer
+
+            except json.decoder.JSONDecodeError as err:
+                print(f'Skipping one of the sources due to an error: {f.name}')
+                print(f'Error msg: {err.msg}')
+
+        if not sourceJson:
+           return
+
+        with open(file_path, 'w') as f:
+            json.dump(sourceJson, f, indent=2, sort_keys=False)
+
     else:  # HTTP status code 4XX/5XX
         print('Download failed: status code {}\n{}'.format(r.status_code, r.text))
 
@@ -38,4 +59,4 @@ if not os.path.exists(destination_dir):
 
 # For each source, download the templates JSON file
 for sourceUrl in get_source_list():
-  download(sourceUrl[1], sourceUrl[0] + '.json')
+  download(sourceUrl[1], sourceUrl[0] + '.json', sourceUrl[2])

+ 6 - 4
lib/list.py

@@ -28,18 +28,20 @@ def generate_app_list():
   markdown_content = ''
   for index, template in enumerate(templates):
       name = template['title'].title()
+      maintainer = template.get('maintainer')
+      maintainer_md_link = f" -- ([Report issues]({maintainer}))" if maintainer else ''
       description = re.sub('[^0-9a-zA-Z]+', ' ', (template['description'] or ''))
       if 'logo' in template and template['logo']:
           logo = f"<img title=\"{description}\" src='{template['logo']}' width='26' height='26' /> "
       else:
-          logo = ' '      
-      markdown_content += f"{index+1}. {logo}**[{name}]({slugify(name)} '{description}')**\n"
+          logo = ' '
+      markdown_content += f"{index+1}. {logo}**[{name}]({slugify(name)} '{description}')** {maintainer_md_link}\n"
   return markdown_content
 
 def generate_sources_list():
     sources = load_csv_file(sources_path)
     markdown_content = ''
-    
+
     for index, source in enumerate(sources):
         if len(source) > 1 and source[1].strip():
           url = source[1].strip()
@@ -47,7 +49,7 @@ def generate_sources_list():
           username = parsed_url.path.split('/')[1]
           avatar = f'<img src="https://github.com/{username}.png?size=40" width="26" height="26" />'
           markdown_content += f"{index + 1}. {avatar} [template]({url}) by [@{username}](https://github.com/{username})\n"
-    
+
     return markdown_content
 
 def insert_content_between_markers(file_path, start_marker, end_marker, content_to_insert):

+ 13 - 13
sources.csv

@@ -1,13 +1,13 @@
-dnburgess_templates, https://raw.githubusercontent.com/dnburgess/self-hosted-template/master/template.json
-qballjos_templates, https://raw.githubusercontent.com/Qballjos/portainer_templates/master/Template/template.json
-selfhostedpro_templates, https://raw.githubusercontent.com/SelfhostedPro/selfhosted_templates/portainer-2.0/Template/template.json
-technorabilia_templates, https://raw.githubusercontent.com/technorabilia/portainer-templates/main/lsio/templates/templates-2.0.json
-mikestraney_templates, https://raw.githubusercontent.com/mikestraney/portainer-templates/master/templates.json
-xneo1_templates, https://raw.githubusercontent.com/xneo1/portainer_templates/master/Template/template.json
-novaspirit_templates, https://raw.githubusercontent.com/novaspirit/pi-hosted/master/pi-hosted_template/template/portainer-v2.json
-donpablonow_templates, https://raw.githubusercontent.com/donpablonow/awesome-saas/master/Template/portainer-v2.json
-mediadepot_templates, https://raw.githubusercontent.com/mediadepot/templates/master/portainer.json
-mycroftwilde_templates, https://raw.githubusercontent.com/mycroftwilde/portainer_templates/master/Template/template.json
-mediadepot_templates, https://raw.githubusercontent.com/mediadepot/templates/master/portainer.json
-shmolf_templates, https://raw.githubusercontent.com/shmolf/portainer-templates/main/templates-2.0.json
-portainer_templates, https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json
+dnburgess_templates, https://raw.githubusercontent.com/dnburgess/self-hosted-template/master/template.json, https://github.com/dnburgess/self-hosted-template/
+qballjos_templates, https://raw.githubusercontent.com/Qballjos/portainer_templates/master/Template/template.json, https://github.com/Qballjos/portainer_templates/
+selfhostedpro_templates, https://raw.githubusercontent.com/SelfhostedPro/selfhosted_templates/portainer-2.0/Template/template.json, https://github.com/SelfhostedPro/selfhosted_templates/
+technorabilia_templates, https://raw.githubusercontent.com/technorabilia/portainer-templates/main/lsio/templates/templates-2.0.json, https://github.com/technorabilia/portainer-templates/
+mikestraney_templates, https://raw.githubusercontent.com/mikestraney/portainer-templates/master/templates.json, https://github.com/mikestraney/portainer-templates/
+xneo1_templates, https://raw.githubusercontent.com/xneo1/portainer_templates/master/Template/template.json, https://github.com/xneo1/portainer_templates/
+novaspirit_templates, https://raw.githubusercontent.com/novaspirit/pi-hosted/master/pi-hosted_template/template/portainer-v2.json, https://github.com/novaspirit/pi-hosted/
+donpablonow_templates, https://raw.githubusercontent.com/donpablonow/awesome-saas/master/Template/portainer-v2.json, https://github.com/donpablonow/awesome-saas/
+mediadepot_templates, https://raw.githubusercontent.com/mediadepot/templates/master/portainer.json, https://github.com/mediadepot/templates/
+mycroftwilde_templates, https://raw.githubusercontent.com/mycroftwilde/portainer_templates/master/Template/template.json, https://github.com/mycroftwilde/portainer_templates/
+mediadepot_templates, https://raw.githubusercontent.com/mediadepot/templates/master/portainer.json, https://github.com/mediadepot/templates/
+shmolf_templates, https://raw.githubusercontent.com/shmolf/portainer-templates/main/templates-2.0.json, https://github.com/shmolf/portainer-templates/
+portainer_templates, https://raw.githubusercontent.com/portainer/templates/master/templates-2.0.json, https://github.com/portainer/templates/

+ 5 - 0
sources/.gitignore

@@ -0,0 +1,5 @@
+*.json
+
+# Keep these
+!example_templates.json
+!lissy93_tempaltes.json