<s> import os <EOL> import re <EOL> import sublime <EOL> from . . package_manager import PackageManager <EOL> class ExistingPackagesCommand ( ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . manager = PackageManager ( ) <EOL> def make_package_list ( self , action = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> packages = self . manager . list_packages ( ) <EOL> if action : <EOL> action += '<STR_LIT:U+0020>' <EOL> package_list = [ ] <EOL> for package in sorted ( packages , key = lambda s : s . lower ( ) ) : <EOL> package_entry = [ package ] <EOL> metadata = self . manager . get_metadata ( package ) <EOL> package_dir = os . path . join ( sublime . packages_path ( ) , package ) <EOL> description = metadata . get ( '<STR_LIT:description>' ) <EOL> if not description : <EOL> description = '<STR_LIT>' <EOL> package_entry . append ( description ) <EOL> version = metadata . get ( '<STR_LIT:version>' ) <EOL> if not version and os . path . exists ( os . path . join ( package_dir , <EOL> '<STR_LIT>' ) ) : <EOL> installed_version = '<STR_LIT>' <EOL> elif not version and os . path . exists ( os . path . join ( package_dir , <EOL> '<STR_LIT>' ) ) : <EOL> installed_version = '<STR_LIT>' <EOL> else : <EOL> installed_version = '<STR_LIT:v>' + version if version else '<STR_LIT>' <EOL> url = metadata . get ( '<STR_LIT:url>' ) <EOL> if url : <EOL> url = '<STR_LIT>' + re . sub ( '<STR_LIT>' , '<STR_LIT>' , url ) <EOL> else : <EOL> url = '<STR_LIT>' <EOL> package_entry . append ( action + installed_version + url ) <EOL> package_list . append ( package_entry ) <EOL> return package_list </s>
