Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.py 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. # Copyright (c) 2008-2010, 2012-2014 LOGILAB S.A. (Paris, FRANCE) <contact@logilab.fr>
  2. # Copyright (c) 2014 Brett Cannon <brett@python.org>
  3. # Copyright (c) 2014 Arun Persaud <arun@nubati.net>
  4. # Copyright (c) 2015-2017 Claudiu Popa <pcmanticore@gmail.com>
  5. # Copyright (c) 2015 Ionel Cristian Maries <contact@ionelmc.ro>
  6. # Copyright (c) 2016 Alexander Pervakov <frost.nzcr4@jagmort.com>
  7. # Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  8. # For details: https://github.com/PyCQA/pylint/blob/master/COPYING
  9. """
  10. %prog [options] <packages>
  11. create UML diagrams for classes and modules in <packages>
  12. """
  13. from __future__ import print_function
  14. import os
  15. import subprocess
  16. import sys
  17. from pylint.config import ConfigurationMixIn
  18. from pylint.pyreverse.inspector import Linker, project_from_files
  19. from pylint.pyreverse.diadefslib import DiadefsHandler
  20. from pylint.pyreverse import writer
  21. from pylint.pyreverse.utils import insert_default_options
  22. OPTIONS = (
  23. ("filter-mode",
  24. dict(short='f', default='PUB_ONLY', dest='mode', type='string',
  25. action='store', metavar='<mode>',
  26. help="""filter attributes and functions according to
  27. <mode>. Correct modes are :
  28. 'PUB_ONLY' filter all non public attributes
  29. [DEFAULT], equivalent to PRIVATE+SPECIAL_A
  30. 'ALL' no filter
  31. 'SPECIAL' filter Python special functions
  32. except constructor
  33. 'OTHER' filter protected and private
  34. attributes""")),
  35. ("class",
  36. dict(short='c', action="append", metavar="<class>", dest="classes", default=[],
  37. help="create a class diagram with all classes related to <class>;\
  38. this uses by default the options -ASmy")),
  39. ("show-ancestors",
  40. dict(short="a", action="store", metavar='<ancestor>', type='int',
  41. help='show <ancestor> generations of ancestor classes not in <projects>')),
  42. ("all-ancestors",
  43. dict(short="A", default=None,
  44. help="show all ancestors off all classes in <projects>")),
  45. ("show-associated",
  46. dict(short='s', action="store", metavar='<ass_level>', type='int',
  47. help='show <ass_level> levels of associated classes not in <projects>')),
  48. ("all-associated",
  49. dict(short='S', default=None,
  50. help='show recursively all associated off all associated classes')),
  51. ("show-builtin",
  52. dict(short="b", action="store_true", default=False,
  53. help='include builtin objects in representation of classes')),
  54. ("module-names",
  55. dict(short="m", default=None, type='yn', metavar='[yn]',
  56. help='include module name in representation of classes')),
  57. # TODO : generate dependencies like in pylint
  58. # ("package-dependencies",
  59. # dict(short="M", action="store", metavar='<package_depth>', type='int',
  60. # help='show <package_depth> module dependencies beyond modules in \
  61. # <projects> (for the package diagram)')),
  62. ("only-classnames",
  63. dict(short='k', action="store_true", default=False,
  64. help="don't show attributes and methods in the class boxes; \
  65. this disables -f values")),
  66. ("output", dict(short="o", dest="output_format", action="store",
  67. default="dot", metavar="<format>",
  68. help="create a *.<format> output file if format available.")),
  69. ("ignore", {'type' : "csv", 'metavar' : "<file[,file...]>",
  70. 'dest' : "black_list", "default" : ('CVS',),
  71. 'help' : "Add files or directories to the blacklist. They "
  72. "should be base names, not paths."}),
  73. ("project", {'default': "", 'type' : 'string', 'short': 'p',
  74. 'metavar': '<project name>', 'help': 'set the project name.'}),
  75. )
  76. # FIXME : quiet mode
  77. #( ('quiet',
  78. #dict(help='run quietly', action='store_true', short='q')), )
  79. def _check_graphviz_available(output_format):
  80. """check if we need graphviz for different output format"""
  81. try:
  82. subprocess.call(['dot', '-V'], stdout=subprocess.PIPE,
  83. stderr=subprocess.PIPE)
  84. except OSError:
  85. print("The output format '%s' is currently not available.\n"
  86. "Please install 'Graphviz' to have other output formats "
  87. "than 'dot' or 'vcg'." % output_format)
  88. sys.exit(32)
  89. class Run(ConfigurationMixIn):
  90. """base class providing common behaviour for pyreverse commands"""
  91. options = OPTIONS
  92. def __init__(self, args):
  93. ConfigurationMixIn.__init__(self, usage=__doc__)
  94. insert_default_options()
  95. args = self.load_command_line_configuration()
  96. if self.config.output_format not in ('dot', 'vcg'):
  97. _check_graphviz_available(self.config.output_format)
  98. sys.exit(self.run(args))
  99. def run(self, args):
  100. """checking arguments and run project"""
  101. if not args:
  102. print(self.help())
  103. return 1
  104. # insert current working directory to the python path to recognize
  105. # dependencies to local modules even if cwd is not in the PYTHONPATH
  106. sys.path.insert(0, os.getcwd())
  107. try:
  108. project = project_from_files(args, project_name=self.config.project,
  109. black_list=self.config.black_list)
  110. linker = Linker(project, tag=True)
  111. handler = DiadefsHandler(self.config)
  112. diadefs = handler.get_diadefs(project, linker)
  113. finally:
  114. sys.path.pop(0)
  115. if self.config.output_format == "vcg":
  116. writer.VCGWriter(self.config).write(diadefs)
  117. else:
  118. writer.DotWriter(self.config).write(diadefs)
  119. return 0
  120. if __name__ == '__main__':
  121. Run(sys.argv[1:])