11# Pckgd
22# Title: Pckgd, A Package Manager
33# Description: A module for managing packages and their updates.
4- # Updates from: github /TenthPres/TouchPointScripts/Pckgd/Pckgd.py
5- # Version: 0.0.3
4+ # Updates from: GitHub /TenthPres/TouchPointScripts/Pckgd/Pckgd.py
5+ # Version: 0.0.4
66# License: AGPL-3.0
77# Author: James at Tenth
88
@@ -30,6 +30,7 @@ def __del__(self):
3030
3131 do_not_edit_demarcation = "========="
3232 dependents = {}
33+ _saved_meta = None
3334
3435 @staticmethod
3536 def find_installed_packages ():
@@ -254,6 +255,9 @@ def get_update_source(self):
254255
255256 return None
256257
258+ def name (self ):
259+ return self .headers ['Title' ] if 'Title' in self .headers else model .SpaceCamelCase (self .filename )
260+
257261 """ Checks if an update is available for this package. Note that this makes at least one, possibly more, HTTP requests. """
258262 def has_update_available (self ):
259263 if self ._has_update_available is None :
@@ -275,8 +279,6 @@ def has_update_available(self):
275279 self ._has_update_available = False
276280 return self ._has_update_available
277281
278- _saved_meta = None
279-
280282 @staticmethod
281283 def _get_saved_meta ():
282284 if Pckgd ._saved_meta is None :
@@ -288,7 +290,7 @@ def _get_saved_meta():
288290 return Pckgd ._saved_meta
289291
290292 @staticmethod
291- def _get_github_repo_metadata (repo_path ):
293+ def _get_github_repo_metadata (repo_path , bypass_cache = False ):
292294 meta = Pckgd ._get_saved_meta ()
293295
294296 if not "github_repo_meta" in meta :
@@ -297,7 +299,7 @@ def _get_github_repo_metadata(repo_path):
297299 if not repo_path in meta ["github_repo_meta" ]:
298300 meta ["github_repo_meta" ][repo_path ] = {}
299301
300- if '_expires' not in meta ["github_repo_meta" ][repo_path ] or meta ["github_repo_meta" ][repo_path ]['_expires' ] < time .time ():
302+ if '_expires' not in meta ["github_repo_meta" ][repo_path ] or meta ["github_repo_meta" ][repo_path ]['_expires' ] < time .time () or bypass_cache :
301303 # query GitHub api to get default branch and other such stuff
302304 url = "https://api.github.com/repos/{}" .format (repo_path )
303305 response = model .RestGet (url , {"Accept" : "application/vnd.github.v3+json" })
@@ -314,8 +316,7 @@ def _save_meta_if_dirty():
314316 del meta ['_dirty' ]
315317 model .WriteContentText ("PckgdCache.json" , json .dumps (meta , indent = 2 ))
316318
317-
318- if model .HttpMethod == "get" and Data .v == "" :
319+ def do_listing_view ():
319320 model .Header = "Package Manager"
320321 model .Title = "Package Manager"
321322
@@ -326,6 +327,9 @@ def _save_meta_if_dirty():
326327 if (not installed ) or (len (installed ) == 0 ):
327328 print ("<p>No packages are currently installed.<p />\n " )
328329
330+ # sort by name
331+ installed .sort (key = lambda p : p .name ().lower ())
332+
329333 for p in installed :
330334 if p .has_dependents ():
331335 continue # skip packages that have dependents; they will be shown with their parent package.
@@ -334,8 +338,7 @@ def _save_meta_if_dirty():
334338 print ("<div class=\" package-header\" style=\" {}\" ></div>\n " .format (p .get_header_style ()))
335339
336340 print ("<div class=\" package-body\" >\n " )
337- name = p .headers ['Title' ] if 'Title' in p .headers else p .filename
338- print ("<h3>{}</h3>\n " .format (name ))
341+ print ("<h3>{}</h3>\n " .format (p .name ()))
339342 if 'Description' in p .headers :
340343 print ("<p>{}</p>\n " .format (p .headers ['Description' ]))
341344
@@ -383,27 +386,30 @@ def _save_meta_if_dirty():
383386
384387 # language=html
385388 print ("""
386- <style>
387- .package-header {
388- width: 100%;
389- padding-top: 25%;
390- }
391- .package-body {
392- padding: 10px;
393- border-width: 0 1px 1px;
394- border-style: solid;
395- border-color: #ccc;
396- height: 14em;
397- margin-bottom: 2em;
398- overflow-y: auto;
399- overflow-x: hidden;
400- }
401- div.package-body h3 {
402- margin-top: 0;
403- }
404- p.package-caption {
405- font-size: 0.75em;
406- opacity: 0.7;
407- }
408- </style>
409- """ )
389+ <style>
390+ .package-header {
391+ width: 100%;
392+ padding-top: 25%;
393+ }
394+ .package-body {
395+ padding: 10px;
396+ border-width: 0 1px 1px;
397+ border-style: solid;
398+ border-color: #ccc;
399+ height: 14em;
400+ margin-bottom: 2em;
401+ overflow-y: auto;
402+ overflow-x: hidden;
403+ }
404+ div.package-body h3 {
405+ margin-top: 0;
406+ }
407+ p.package-caption {
408+ font-size: 0.75em;
409+ opacity: 0.7;
410+ }
411+ </style>
412+ """ )
413+
414+ if model .HttpMethod == "get" and Data .v == "" :
415+ do_listing_view ()
0 commit comments