Skip to content

Commit

Permalink
Add coala.py
Browse files Browse the repository at this point in the history
Moves the main function to 'coalib.coala' module to separate
functionality from command line invocation.
To support invocations for all platforms (Windows and Linux), this
commit creates both files, 'coala' and 'coala.py'. These only point to
the main function in 'coalib.coala'.

References #196.
  • Loading branch information
Makman2 committed May 15, 2015
1 parent 0576226 commit 27d7537
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 66 deletions.
67 changes: 2 additions & 65 deletions coala
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
from coalib.output.ClosableObject import ClosableObject

from coalib.output.printers.ConsolePrinter import ConsolePrinter
from coalib.misc.StringConstants import StringConstants
from coalib.processes.SectionExecutor import SectionExecutor
from coalib.settings.SectionManager import SectionManager


from coalib.misc.i18n import _

from coalib.coala import main

if __name__ == "__main__":
log_printer = None
interactor = None
exitcode = 0
try:
did_nothing = True
yielded_results = False
sections, local_bears, global_bears, targets, interactor, log_printer \
= SectionManager().run()
for section_name in sections:
section = sections[section_name]
if not section.is_enabled(targets):
continue

yielded_results = yielded_results or SectionExecutor(
section=section,
global_bear_list=global_bears[section_name],
local_bear_list=local_bears[section_name],
interactor=interactor,
log_printer=log_printer).run()[0]
did_nothing = False

if did_nothing:
interactor.did_nothing()

if yielded_results:
exitcode = 1
except KeyboardInterrupt: # Ctrl+C
print(_("Program terminated by user."))
exitcode = 130
except EOFError: # Ctrl+D
print(_("Found EOF. Exiting gracefully."))
except SystemExit as e:
exitcode = e.code
except:
exception = sys.exc_info()[1]
UNKNOWN_ERROR = _("An unknown error occurred.") + " " + \
StringConstants.THIS_IS_A_BUG
DESCRIPTION = _("During execution of coala an exception was raised. "
"This should never happen. When asked for, the "
"following information may help investigating:")

if log_printer is None:
log_printer = ConsolePrinter()

log_printer.log_exception(UNKNOWN_ERROR + " " + DESCRIPTION,
exception)
exitcode = 255

if log_printer is not None and isinstance(log_printer, ClosableObject):
log_printer.close()
if interactor is not None and isinstance(interactor, ClosableObject):
interactor.close()

exit(exitcode)
main()
19 changes: 19 additions & 0 deletions coala.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from coalib.coala import main

if __name__ == "__main__":
main()
83 changes: 83 additions & 0 deletions coalib/coala.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
from coalib.output.ClosableObject import ClosableObject

from coalib.output.printers.ConsolePrinter import ConsolePrinter
from coalib.misc.StringConstants import StringConstants
from coalib.processes.SectionExecutor import SectionExecutor
from coalib.settings.SectionManager import SectionManager

from coalib.misc.i18n import _


def main():
log_printer = None
interactor = None
exitcode = 0
try:
did_nothing = True
yielded_results = False
sections, local_bears, global_bears, targets, interactor, log_printer \
= SectionManager().run()
for section_name in sections:
section = sections[section_name]
if not section.is_enabled(targets):
continue

yielded_results = yielded_results or SectionExecutor(
section=section,
global_bear_list=global_bears[section_name],
local_bear_list=local_bears[section_name],
interactor=interactor,
log_printer=log_printer).run()[0]
did_nothing = False

if did_nothing:
interactor.did_nothing()

if yielded_results:
exitcode = 1
except KeyboardInterrupt: # Ctrl+C
print(_("Program terminated by user."))
exitcode = 130
except EOFError: # Ctrl+D
print(_("Found EOF. Exiting gracefully."))
except SystemExit as e:
exitcode = e.code
except:
exception = sys.exc_info()[1]
UNKNOWN_ERROR = _("An unknown error occurred.") + " " + \
StringConstants.THIS_IS_A_BUG
DESCRIPTION = _("During execution of coala an exception was raised. "
"This should never happen. When asked for, the "
"following information may help investigating:")

if log_printer is None:
log_printer = ConsolePrinter()

log_printer.log_exception(UNKNOWN_ERROR + " " + DESCRIPTION,
exception)
exitcode = 255

if log_printer is not None and isinstance(log_printer, ClosableObject):
log_printer.close()
if interactor is not None and isinstance(interactor, ClosableObject):
interactor.close()

exit(exitcode)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
maintainer='Lasse Schuirmann, Fabian Neuschmidt',
maintainer_email='lasse.schuirmann@gmail.com, fabian@neuschmidt.de',
url='http://coala.schuirmann.net/',
scripts=['coala'],
scripts=['coala.py', 'coala'],
packages=['bears',
'bears.codeclone_detection',
'bears.misc',
Expand Down

1 comment on commit 27d7537

@sils
Copy link
Member

@sils sils commented on 27d7537 May 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack

Please sign in to comment.