2222]
2323
2424epilog = """
25- script mode output:
26- latest The latest package is installed
27- noversion Failed to get the latest version of the package, but the package is installed
28- nomatch The version of the package installed in local does not match one of the latest
29- failed Package not installed
25+ exit code:
26+ 0 (latest) The latest package is installed
27+ 1 (noversion) Failed to get the latest version of the package, but the package is installed
28+ 2 (nomatch) The version of the package installed in local does not match one of the latest
29+ 3 (failed) Package not installed
30+ 4 Other error
3031"""
3132
3233def msg_info (string ):
@@ -54,30 +55,27 @@ def compare(package):
5455 pkg_from_sync = get_from_syncdb (package )
5556
5657 if pkg_from_local is None :
57- if args .script :
58- return ["failed" ]
59- else :
58+ # failed
59+ if not args .script :
6060 msg_error (f"{ package } is not installed." )
61- return 1
61+ return 3
62+
6263 elif pkg_from_sync is None :
63- if args .script :
64- return ["noversion" ]
65- else :
64+ # noversion
65+ if not args .script :
6666 msg_warn (f"Failed to get the latest version of { package } ." )
67- return 1
68-
67+ return 1
68+
6969 if pkg_from_local .version == pkg_from_sync .version :
70- if args .script :
71- return ["latest" , pkg_from_local .version ]
72- else :
70+ # latest
71+ if not args .script :
7372 msg_info (f"The latest version of { package } is installed." )
74- return 0
73+ return 0
7574 else :
76- if args .script :
77- return ["nomatch" , pkg_from_local .version , pkg_from_sync .version ]
78- else :
75+ # nomatch
76+ if not args .script :
7977 msg_warn (f"The version of { package } does not match one of the latest.\n Local: { pkg_from_local .version } Latest: { pkg_from_sync .version } " )
80- return 1
78+ return 2
8179
8280if __name__ == "__main__" :
8381 script_dir = os .path .dirname (os .path .abspath (__file__ ))
@@ -111,7 +109,7 @@ def compare(package):
111109 exit ()
112110 else :
113111 msg_error ("pyalpm is not installed." )
114- sys .exit (1 )
112+ sys .exit (4 )
115113
116114 handle = pyalpm .Handle ("." , "/var/lib/pacman" )
117115
@@ -121,9 +119,12 @@ def compare(package):
121119 localdb = handle .get_localdb ()
122120 syncdbs = handle .get_syncdbs ()
123121
124- if args .script :
125- result = compare (args .package )
126- print (" " .join (result ))
127- else :
128- return_code = compare (args .package )
129- sys .exit (return_code )
122+ #if args.script:
123+ # result = compare(args.package)
124+ # print(" ".join(result))
125+ #else:
126+ # return_code = compare(args.package)
127+ # sys.exit(return_code)
128+
129+ return_code = compare (args .package )
130+ sys .exit (return_code )
0 commit comments