build: Generate the list of libraries
This commit is contained in:
		
							parent
							
								
									1a29f856e4
								
							
						
					
					
						commit
						2b301ca032
					
				
							
								
								
									
										71
									
								
								generate_licenses.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								generate_licenses.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,71 @@ | |||||||
|  | import yaml | ||||||
|  | import requests | ||||||
|  | 
 | ||||||
|  | def render_library(obj, _license): | ||||||
|  |     return '\tLibrary(name: "{}", license: "{}", url: "{}")'.format( | ||||||
|  |         obj["name"], | ||||||
|  |         _license, | ||||||
|  |         obj["url"] | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  | def homepage_wrapper(obj): | ||||||
|  |     if "homepage" in obj["latest"]["pubspec"]: | ||||||
|  |         return obj["latest"]["pubspec"]["homepage"] | ||||||
|  |     elif "repository" in obj["latest"]["pubspec"]: | ||||||
|  |         return obj["latest"]["pubspec"]["repository"] | ||||||
|  | 
 | ||||||
|  |     raise Exception("No homepage or repository for " + obj["name"]) | ||||||
|  | 
 | ||||||
|  | def get_library_data(pkg): | ||||||
|  |     req = requests.get("https://pub.dev/api/packages/" + pkg) | ||||||
|  |      | ||||||
|  |     return { | ||||||
|  |         "name": req.json()["name"], | ||||||
|  |         "url": homepage_wrapper(req.json()) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | def get_license(pkg): | ||||||
|  |     req = requests.get("https://pub.dev/packages/" + pkg + "/license") | ||||||
|  | 
 | ||||||
|  |     if "Apache-2.0" in req.text: | ||||||
|  |         return "Apache-2.0" | ||||||
|  |     elif "BSD-3-Clause" in req.text: | ||||||
|  |         return "BSD-3-Clause" | ||||||
|  |     elif "MIT" in req.text: | ||||||
|  |         return "MIT" | ||||||
|  | 
 | ||||||
|  |     raise Exception("Unknown license for " + pkg) | ||||||
|  | 
 | ||||||
|  | def mklib(pkg): | ||||||
|  |     print(pkg) | ||||||
|  |     return render_library(get_library_data(pkg), get_license(pkg)) | ||||||
|  |      | ||||||
|  | #print(get_license("flutter_settings_ui")) | ||||||
|  | #print(get_library_data("flutter_settings_ui")) | ||||||
|  | 
 | ||||||
|  | def main(): | ||||||
|  |     with open("pubspec.yaml", "r") as f: | ||||||
|  |         pubspec = yaml.load(f.read(), Loader=yaml.Loader) | ||||||
|  | 
 | ||||||
|  |     libs = [ mklib(pkg) for pkg in pubspec["dependencies"] if pkg not in ("flutter",) ] | ||||||
|  |     devlibs = [ mklib(pkg) for pkg in pubspec["dev_dependencies"] if pkg not in ("flutter_test", "test",) ] | ||||||
|  | 
 | ||||||
|  |     extra = pubspec.get("extra_licenses", {}) | ||||||
|  |     extralibs = [ render_library({ "name": obj, "url": extra[obj]["url"] }, extra[obj]["license"]) for obj in extra ] | ||||||
|  | 
 | ||||||
|  |     generated = ''' | ||||||
|  | // Generated by generate_providers.py | ||||||
|  | import "dart:collection"; | ||||||
|  | import "package:moxxyv2/data/libraries.dart"; | ||||||
|  | 
 | ||||||
|  | final List<Library> usedLibraryList = [ | ||||||
|  | {} | ||||||
|  | ]; | ||||||
|  | '''.format(",\n".join(libs + devlibs + extralibs)); | ||||||
|  | 
 | ||||||
|  |     with open("lib/data/generated/licenses.dart", "w") as f: | ||||||
|  |         f.write(generated) | ||||||
|  |     #print(generated) | ||||||
|  | 
 | ||||||
|  | if __name__ == "__main__": | ||||||
|  |     main() | ||||||
							
								
								
									
										7
									
								
								lib/data/libraries.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								lib/data/libraries.dart
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,7 @@ | |||||||
|  | class Library { | ||||||
|  |   final String name; | ||||||
|  |   final String license; | ||||||
|  |   final String url; | ||||||
|  | 
 | ||||||
|  |   const Library({ required this.name, required this.license, required this.url }); | ||||||
|  | } | ||||||
| @ -2,100 +2,12 @@ import "dart:collection"; | |||||||
| import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||||
| import "package:moxxyv2/ui/constants.dart"; | import "package:moxxyv2/ui/constants.dart"; | ||||||
| import "package:moxxyv2/ui/widgets/topbar.dart"; | import "package:moxxyv2/ui/widgets/topbar.dart"; | ||||||
|  | import "package:moxxyv2/data/libraries.dart"; | ||||||
|  | import "package:moxxyv2/data/generated/licenses.dart"; | ||||||
| 
 | 
 | ||||||
| import "package:flutter_settings_ui/flutter_settings_ui.dart"; | import "package:flutter_settings_ui/flutter_settings_ui.dart"; | ||||||
| import "package:url_launcher/url_launcher.dart"; | import "package:url_launcher/url_launcher.dart"; | ||||||
| 
 | 
 | ||||||
| // TODO: Maybe also include the License text |  | ||||||
| 
 |  | ||||||
| class Library { |  | ||||||
|   final String name; |  | ||||||
|   final String license; |  | ||||||
|   final String url; |  | ||||||
| 
 |  | ||||||
|   const Library({ required this.name, required this.license, required this.url }); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // TODO: Maybe generate this list during build |  | ||||||
| const List<Library> _USED_LIBRARIES = [ |  | ||||||
|   Library( |  | ||||||
|     name: "flutter_settings_ui", |  | ||||||
|     license: "Apache-2.0", |  | ||||||
|     url: "https://github.com/juliansteenbakker/flutter_settings_ui" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "flutter_speed_dial", |  | ||||||
|     license: "MIT", |  | ||||||
|     url: "https://github.com/darioielardi/flutter_speed_dial" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "get_it", |  | ||||||
|     license: "MIT", |  | ||||||
|     url: "https://github.com/fluttercommunity/get_it" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "redux", |  | ||||||
|     license: "MIT", |  | ||||||
|     url: "https://github.com/fluttercommunity/redux.dart" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "flutter_redux", |  | ||||||
|     license: "MIT", |  | ||||||
|     url: "https://github.com/brianegan/flutter_redux" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "badges", |  | ||||||
|     license: "Apache-2.0", |  | ||||||
|     url: "https://github.com/yadaniyil/flutter_badges" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "url_launcher", |  | ||||||
|     license: "BSD-3-Clause", |  | ||||||
|     url: "https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "flutter_launcher_icons", |  | ||||||
|     license: "MIT", |  | ||||||
|     url: "https://github.com/fluttercommunity/flutter_launcher_icons" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "flutter_lints", |  | ||||||
|     license: "BSD-3-Clause", |  | ||||||
|     url: "https://github.com/flutter/packages/tree/master/packages/flutter_lints" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "floor", |  | ||||||
|     license: "Apache-2.0", |  | ||||||
|     url: "https://github.com/vitusortner/floor" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "floor_generator", |  | ||||||
|     license: "Apache-2.0", |  | ||||||
|     url: "https://github.com/vitusortner/floor" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "build_runner", |  | ||||||
|     license: "BSD-3-Clause", |  | ||||||
|     url: "https://github.com/dart-lang/build/tree/master/build_runner" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     name: "undraw.co", |  | ||||||
|     license: "custom license", |  | ||||||
|     url: "https://undraw.co/" |  | ||||||
|   ), |  | ||||||
|   Library( |  | ||||||
|     // TODO: This is dangerous |  | ||||||
|     name: "xmpp-providers", |  | ||||||
|     license: "unknown license", |  | ||||||
|     url: "https://invent.kde.org/melvo/xmpp-providers" |  | ||||||
|   ), |  | ||||||
|    Library( |  | ||||||
|     name: "qr_flutter", |  | ||||||
|     license: "BSD-3-Clause", |  | ||||||
|     url: "https://github.com/theyakka/qr.flutter" |  | ||||||
|   )  |  | ||||||
| ]; |  | ||||||
| 
 |  | ||||||
| class LicenseRow extends StatelessWidget { | class LicenseRow extends StatelessWidget { | ||||||
|   final Library library; |   final Library library; | ||||||
| 
 | 
 | ||||||
| @ -124,8 +36,8 @@ class SettingsLicensesPage extends StatelessWidget { | |||||||
|     return Scaffold( |     return Scaffold( | ||||||
|       appBar: BorderlessTopbar.simple(title: "Licenses"), |       appBar: BorderlessTopbar.simple(title: "Licenses"), | ||||||
|       body: ListView.builder( |       body: ListView.builder( | ||||||
|         itemCount: _USED_LIBRARIES.length, |         itemCount: usedLibraryList.length, | ||||||
|         itemBuilder: (context, index) => LicenseRow(library: _USED_LIBRARIES[index]) |         itemBuilder: (context, index) => LicenseRow(library: usedLibraryList[index]) | ||||||
|       ) |       ) | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -46,6 +46,15 @@ dev_dependencies: | |||||||
|   test: |   test: | ||||||
|   flutter_launcher_icons: ^0.9.2 |   flutter_launcher_icons: ^0.9.2 | ||||||
| 
 | 
 | ||||||
|  | extra_licenses: | ||||||
|  |   undraw.co: | ||||||
|  |     license: "custom license" | ||||||
|  |     url: "https://undraw.co" | ||||||
|  |   xmpp-providers: | ||||||
|  |     # TODO: Dangerous | ||||||
|  |     license: "unknown license" | ||||||
|  |     url: "https://invent.kde.org/melvo/xmpp-providers" | ||||||
|  |   | ||||||
| flutter: | flutter: | ||||||
|   uses-material-design: true |   uses-material-design: true | ||||||
|   assets: |   assets: | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user