Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1#!python 

2""" 

3script which goes through all installed modules 

4""" 

5from __future__ import print_function 

6import sys 

7import os 

8import argparse 

9 

10 

11def get_parser(): 

12 """ 

13 defines the way to parse the script ``pymy_status`` 

14 """ 

15 typstr = str # unicode# 

16 parser = argparse.ArgumentParser( 

17 description='information about installed modules') 

18 parser.add_argument( 

19 '-o', 

20 '--out', 

21 default="python_module.xlsx", 

22 type=typstr, 

23 help='output the results into a file (required pandas)') 

24 parser.add_argument( 

25 '-p', 

26 '--pypi', 

27 default=True, 

28 type=bool, 

29 help='checks the version on PyPi') 

30 parser.add_argument( 

31 'module', 

32 nargs="*", 

33 default="all", 

34 help='update only the list of modules included in this list or all modules if not specified or equal to all') 

35 parser.add_argument( 

36 '--set', 

37 default="-", 

38 type=typstr, 

39 help='set of module to install, see documentation of function get_name_set to get a comprehensive list, ' + 

40 'this option is ignored if a module is specified on the command line') 

41 return parser 

42 

43 

44def do_main(list_module=None, outfile="python_module.xlsx", pypi=True): 

45 """ 

46 Calls function @see fn update_all but is meant to be added to scripts folder. 

47 

48 @param list_module list of modules to update or None for all 

49 @param outfile output the results into a flat file or an excel file (required pandas) 

50 @param pypi check version on PyPi 

51 """ 

52 try: 

53 from pymyinstall.installhelper import get_installed_modules 

54 except ImportError: 

55 pfolder = os.path.normpath(os.path.join( 

56 os.path.abspath(os.path.dirname(__file__)), "..", "..")) 

57 sys.path.append(pfolder) 

58 if "pymyinstall" in sys.modules: 

59 del sys.modules["pymyinstall"] 

60 if "pymyinstall.installhelper" in sys.modules: 

61 del sys.modules["pymyinstall.installhelper"] 

62 from pymyinstall.installhelper import get_installed_modules 

63 if list_module is not None and len(list_module) == 0: 

64 list_module = None 

65 if outfile: 

66 import pandas 

67 res = get_installed_modules(short_list=list_module, fLOG=print, pypi=True) 

68 if outfile: 

69 df = pandas.DataFrame(res) 

70 cols = list(df.columns) 

71 cols.sort() 

72 df = df[cols] 

73 if ".xls" in os.path.split(outfile)[-1]: 

74 print("Saving into:", outfile) 

75 df.to_excel(outfile, index=False) 

76 else: 

77 print("Saving into (sep=tab, encoding=utf-8):", outfile) 

78 df.to_csv(outfile, seo="\t", encoding="utf-8", index=False) 

79 

80 

81def main(): 

82 """ 

83 calls function @see fn update_all but is meant to be added to scripts folder, 

84 parse command line arguments 

85 """ 

86 parser = get_parser() 

87 try: 

88 res = parser.parse_args() 

89 except SystemExit: 

90 print(parser.format_usage()) 

91 res = None 

92 

93 if res is not None: 

94 list_module = None if res.module in [ 

95 "all", "", "-", None, []] else res.module 

96 if list_module is None and res.set is not None and len(res.set) > 0 and res.set != "-": 

97 list_module = res.set 

98 do_main(list_module=list_module, outfile=res.out, pypi=res.pypi) 

99 

100 

101if __name__ == "__main__": 

102 main()