コード例 #1
0
def _signal_update_status(status):

    update_found, msg = status
    if update_found is False:
        _cfg = gmCfgINI.gmCfgData()
        gmDispatcher.send(signal='statustext',
                          msg=_('Your client (%s) is up to date.') %
                          _cfg.get(option='client_version'))
        return

    gmGuiHelpers.gm_show_info(msg, _('Checking for client updates'))
コード例 #2
0
def _get_update_status():
    url = gmCfgDB.get4workplace(
        option='horstspace.update.url',
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        default='https://www.gnumed.de/downloads/gnumed-versions.txt')
    consider_latest_branch = gmCfgDB.get4workplace(
        option='horstspace.update.consider_latest_branch',
        workplace=gmPraxis.gmCurrentPraxisBranch().active_workplace,
        default=True)
    _cfg = gmCfgINI.gmCfgData()
    update_found, msg = gmNetworkTools.check_for_update(
        url=url,
        current_branch=_cfg.get(option='client_branch'),
        current_version=_cfg.get(option='client_version'),
        consider_latest_branch=consider_latest_branch)
    return update_found, msg
コード例 #3
0
ファイル: gmTopPanel.py プロジェクト: ncqgm/gnumed
    def __init_ui(self):
        cfg = gmCfgINI.gmCfgData()
        if cfg.get(option='slave'):
            self._TCTRL_patient_selector.SetEditable(0)
            self._TCTRL_patient_selector.SetToolTip(None)

        if sys.platform == 'darwin':
            _log.debug('adjusting font size on Mac for top panel parts')
            for ctrl in [
                    self._TCTRL_patient_selector, self._LBL_age,
                    self._LBL_allergies, self._TCTRL_allergies
            ]:
                curr_font = ctrl.GetFont()
                mac_font = wx.Font(curr_font.GetNativeFontInfo())
                mac_font.SetPointSize(pointSize=int(curr_font.GetPointSize() /
                                                    0.8))
                ctrl.SetFont(mac_font)

        self.__lab_panel = self.__get_lab_panel()
コード例 #4
0
	def print_forms():
		# anything to do ?
		files2print = []
		form_names = []
		for form in forms:
			files2print.extend(form.final_output_filenames)
			form_names.append('%s (%s)' % (form.template['name_long'], form.template['external_version']))
		if len(files2print) == 0:
			return True
		# print
		_cfg = gmCfgINI.gmCfgData()
		printed = gmPrinting.print_files(filenames = files2print, jobtype = jobtype, verbose = _cfg.get(option = 'debug'))
		if not printed:
			gmGuiHelpers.gm_show_error (
				aMessage = _('Error printing documents.'),
				aTitle = _('Printing [%s]') % jobtype
			)
			return False
		soap_lines.append(_('Printed: %s') % ', '.join(form_names))
		return True
コード例 #5
0
ファイル: gmMimeLib.py プロジェクト: ncqgm/gnumed
def guess_ext_by_mimetype(mimetype=''):
    """Return file extension based on what the OS thinks a file of this mimetype should end in."""

    # ask system first
    ext = mimetypes.guess_extension(mimetype)
    if ext is not None:
        _log.debug('<%s>: %s', mimetype, ext)
        return ext

    _log.error("<%s>: no suitable file extension known to the OS" % mimetype)
    # try to help the OS a bit
    cfg = gmCfgINI.gmCfgData()
    ext = cfg.get(group='extensions',
                  option=mimetype,
                  source_order=[('user-mime', 'return'),
                                ('system-mime', 'return')])
    if ext is not None:
        _log.debug('<%s>: %s', mimetype, ext)
        return ext

    _log.error("<%s>: no suitable file extension found in config files",
               mimetype)
    return ext
コード例 #6
0
ファイル: gnumed.py プロジェクト: ncqgm/gnumed
def setup_cli():
    from Gnumed.pycommon import gmCfgINI

    global _cfg
    _cfg = gmCfgINI.gmCfgData()
    _cfg.add_cli(short_options=_known_short_options,
                 long_options=_known_long_options)

    val = _cfg.get(option='--debug', source_order=[('cli', 'return')])
    if val is None:
        val = False
    _cfg.set_option(option='debug', value=val)

    val = _cfg.get(option='--slave', source_order=[('cli', 'return')])
    if val is None:
        val = False
    _cfg.set_option(option='slave', value=val)

    val = _cfg.get(option='--skip-update-check',
                   source_order=[('cli', 'return')])
    if val is None:
        val = False
    _cfg.set_option(option='skip-update-check', value=val)

    val = _cfg.get(option='--hipaa', source_order=[('cli', 'return')])
    if val is None:
        val = False
    _cfg.set_option(option='hipaa', value=val)

    val = _cfg.get(option='--local-import', source_order=[('cli', 'return')])
    if val is None:
        val = False
    _cfg.set_option(option='local-import', value=val)

    _cfg.set_option(option='client_version', value=current_client_version)

    _cfg.set_option(option='client_branch', value=current_client_branch)
コード例 #7
0
import wx

if __name__ == '__main__':
    sys.path.insert(0, '../../')
    _ = lambda x: x
from Gnumed.pycommon import gmGuiBroker
from Gnumed.pycommon import gmCfgDB
from Gnumed.pycommon import gmCfgINI
from Gnumed.pycommon import gmDispatcher
from Gnumed.pycommon import gmTools

from Gnumed.business import gmPerson
from Gnumed.business import gmPraxis

_cfg = gmCfgINI.gmCfgData()

_log = logging.getLogger('gm.ui')


#==============================================================================
class cLoadProgressBar(wx.ProgressDialog):
    def __init__(self, nr_plugins):
        wx.ProgressDialog.__init__(
            self,
            title=_("GNUmed: configuring [%s] (%s plugins)") %
            (gmPraxis.gmCurrentPraxisBranch().active_workplace, nr_plugins),
            message=_(
                "loading list of plugins                               "),
            maximum=nr_plugins,
            parent=None,
コード例 #8
0
ファイル: gmNetworkTools.py プロジェクト: ncqgm/gnumed
def check_for_update(url=None,
                     current_branch=None,
                     current_version=None,
                     consider_latest_branch=False):
    """Check for new releases at <url>.

	Returns (bool, text).
	True: new release available
	False: up to date
	None: don't know
	"""
    if current_version is None:
        _log.debug('<current_version> is None, currency unknown')
        return (None, None)

    if current_version.casefold() in [
            'git head', 'head', 'tip', 'dev', 'devel'
    ]:
        _log.debug('[%s] always considered up to date', current_version)
        return (False, None)

    try:
        remote_file = urllib.request.urlopen(url)
    except (urllib.error.URLError, ValueError, OSError, IOError):
        # IOError: socket.error
        _log.exception("cannot retrieve version file from [%s]", url)
        return (None,
                _('Cannot retrieve version information from:\n\n%s') % url)

    _log.debug('retrieving version information from [%s]', url)

    cfg = gmCfgINI.gmCfgData()
    try:
        #remote_file.read().decode(resource.headers.get_content_charset())
        cfg.add_stream_source(source='gm-versions',
                              stream=remote_file,
                              encoding=u'utf8')
    except (UnicodeDecodeError):
        remote_file.close()
        _log.exception("cannot read version file from [%s]", url)
        return (None, _('Cannot read version information from:\n\n%s') % url)

    remote_file.close()

    latest_branch = cfg.get('latest branch',
                            'branch',
                            source_order=[('gm-versions', 'return')])
    latest_release_on_latest_branch = cfg.get('branch %s' % latest_branch,
                                              'latest release',
                                              source_order=[('gm-versions',
                                                             'return')])
    latest_release_on_current_branch = cfg.get('branch %s' % current_branch,
                                               'latest release',
                                               source_order=[('gm-versions',
                                                              'return')])

    cfg.remove_source('gm-versions')

    _log.info('current release: %s', current_version)
    _log.info('current branch: %s', current_branch)
    _log.info('latest release on current branch: %s',
              latest_release_on_current_branch)
    _log.info('latest branch: %s', latest_branch)
    _log.info('latest release on latest branch: %s',
              latest_release_on_latest_branch)

    # anything known ?
    no_release_information_available = (
        ((latest_release_on_current_branch is None) and
         (latest_release_on_latest_branch is None))
        or (not consider_latest_branch and
            (latest_release_on_current_branch is None)))
    if no_release_information_available:
        _log.warning('no release information available')
        msg = _('There is no version information available from:\n\n%s') % url
        return (None, msg)

    # up to date ?
    if consider_latest_branch:
        _log.debug('latest branch taken into account')
        if latest_release_on_latest_branch is None:
            if compare_versions(latest_release_on_current_branch,
                                current_version) in [-1, 0]:
                _log.debug(
                    'up to date: current version >= latest version on current branch and no latest branch available'
                )
                return (False, None)
        else:
            if compare_versions(latest_release_on_latest_branch,
                                current_version) in [-1, 0]:
                _log.debug(
                    'up to date: current version >= latest version on latest branch'
                )
                return (False, None)
    else:
        _log.debug('latest branch not taken into account')
        if compare_versions(latest_release_on_current_branch,
                            current_version) in [-1, 0]:
            _log.debug(
                'up to date: current version >= latest version on current branch'
            )
            return (False, None)

    new_release_on_current_branch_available = (
        (latest_release_on_current_branch is not None) and (compare_versions(
            latest_release_on_current_branch, current_version) == 1))
    _log.info(
        '%snew release on current branch available',
        gmTools.bool2str(new_release_on_current_branch_available, '', 'no '))

    new_release_on_latest_branch_available = ((latest_branch is not None) and (
        (latest_branch > current_branch) or
        ((latest_branch == current_branch) and (compare_versions(
            latest_release_on_latest_branch, current_version) == 1))))
    _log.info(
        '%snew release on latest branch available',
        gmTools.bool2str(new_release_on_latest_branch_available, '', 'no '))

    if not (new_release_on_current_branch_available
            or new_release_on_latest_branch_available):
        _log.debug('up to date: no new releases available')
        return (False, None)

    # not up to date
    msg = _('A new version of GNUmed is available.\n\n')
    msg += _(' Your current version: "%s"\n') % current_version
    if consider_latest_branch:
        if new_release_on_current_branch_available:
            msg += '\n'
            msg += _(' New version: "%s"') % latest_release_on_current_branch
            msg += '\n'
            msg += _(' - bug fixes only\n')
            msg += _(' - database fixups may be needed\n')
        if new_release_on_latest_branch_available:
            if current_branch != latest_branch:
                msg += '\n'
                msg += _(
                    ' New version: "%s"') % latest_release_on_latest_branch
                msg += '\n'
                msg += _(' - bug fixes and new features\n')
                msg += _(' - database upgrade required\n')
    else:
        msg += '\n'
        msg += _(' New version: "%s"') % latest_release_on_current_branch
        msg += '\n'
        msg += _(' - bug fixes only\n')
        msg += _(' - database fixups may be needed\n')

    msg += '\n\n'
    msg += _('Note, however, that this version may not yet\n'
             'be available *pre-packaged* for your system.')

    msg += '\n\n'
    msg += _('Details are found on <https://www.gnumed.de>.\n')
    msg += '\n'
    msg += _('Version information loaded from:\n\n %s') % url

    return (True, msg)
コード例 #9
0
def mail_log(parent=None,
             comment=None,
             helpdesk=None,
             sender=None,
             exception=None):

    if (comment is None) or (comment.strip() == ''):
        comment = wx.GetTextFromUser(message=_(
            'Please enter a short note on what you\n'
            'were about to do in GNUmed:'),
                                     caption=_('Sending bug report'),
                                     parent=parent)
        if comment.strip() == '':
            comment = '<user did not comment on bug report>'

    receivers = []
    if helpdesk is not None:
        receivers = regex.findall('[\S]+@[\S]+',
                                  helpdesk.strip(),
                                  flags=regex.UNICODE)
    if len(receivers) == 0:
        if _is_public_database:
            receivers = ['*****@*****.**']

    receiver_string = wx.GetTextFromUser(message=_(
        'Edit the list of email addresses to send the\n'
        'bug report to (separate addresses by spaces).\n'
        '\n'
        'Note that <*****@*****.**> refers to\n'
        'the public (!) GNUmed bugs mailing list.'),
                                         caption=_('Sending bug report'),
                                         default_value=','.join(receivers),
                                         parent=parent)
    if receiver_string.strip() == '':
        return

    receivers = regex.findall('[\S]+@[\S]+',
                              receiver_string,
                              flags=regex.UNICODE)

    dlg = gmGuiHelpers.c2ButtonQuestionDlg(
        parent,
        -1,
        caption=_('Sending bug report'),
        question=_('Your bug report will be sent to:\n'
                   '\n'
                   '%s\n'
                   '\n'
                   'Make sure you have reviewed the log file for potentially\n'
                   'sensitive information before sending out the bug report.\n'
                   '\n'
                   'Note that emailing the report may take a while depending\n'
                   'on the speed of your internet connection.\n') %
        '\n'.join(receivers),
        button_defs=[{
            'label': _('Send report'),
            'tooltip': _('Yes, send the bug report.')
        }, {
            'label': _('Cancel'),
            'tooltip': _('No, do not send the bug report.')
        }],
        show_checkbox=True,
        checkbox_msg=_('include log file in bug report'))
    dlg._CHBOX_dont_ask_again.SetValue(_is_public_database)
    go_ahead = dlg.ShowModal()
    if go_ahead == wx.ID_NO:
        dlg.DestroyLater()
        return

    include_log = dlg._CHBOX_dont_ask_again.GetValue()
    if not _is_public_database:
        if include_log:
            result = gmGuiHelpers.gm_show_question(
                _('The database you are connected to is marked as\n'
                  '"in-production with controlled access".\n'
                  '\n'
                  'You indicated that you want to include the log\n'
                  'file in your bug report. While this is often\n'
                  'useful for debugging the log file might contain\n'
                  'bits of patient data which must not be sent out\n'
                  'without de-identification.\n'
                  '\n'
                  'Please confirm that you want to include the log !'),
                _('Sending bug report'))
            include_log = (result is True)

    if sender is None:
        sender = _('<not supplied>')
    else:
        if sender.strip() == '':
            sender = _('<not supplied>')

    if exception is None:
        exc_info = ''
    else:
        t, v, tb = exception
        exc_info = 'Exception:\n\n type: %s\n value: %s\n\nTraceback:\n\n%s' % (
            t, v, ''.join(traceback.format_tb(tb)))

    msg = """\
Report sent via GNUmed's handler for unexpected exceptions.

user comment  : %s

client version: %s

system account: %s
staff member  : %s
sender email  : %s

 # enable Launchpad bug tracking
 affects gnumed
 tag automatic-report
 importance medium

%s
""" % (comment, _client_version, _local_account, _staff_name, sender, exc_info)
    if include_log:
        _log.error(comment)
        _log.warning('syncing log file for emailing')
        gmLog2.flush()
        attachments = [[_logfile_name, 'text/plain', 'quoted-printable']]
    else:
        attachments = None

    dlg.DestroyLater()

    wx.BeginBusyCursor()
    _cfg = gmCfgINI.gmCfgData()
    try:
        gmNetworkTools.compose_and_send_email(
            sender='%s <%s>' %
            (_staff_name, gmNetworkTools.default_mail_sender),
            receiver=receivers,
            subject='<bug>: %s' % comment,
            message=msg,
            server=gmNetworkTools.default_mail_server,
            auth={
                'user': gmNetworkTools.default_mail_sender,
                'password': '******'
            },
            debug=_cfg.get(option='debug'),
            attachments=attachments)
        gmDispatcher.send(signal='statustext',
                          msg=_('Bug report has been emailed.'))
    except Exception:
        _log.exception('cannot send bug report')
        gmDispatcher.send(signal='statustext',
                          msg=_('Bug report COULD NOT be emailed.'))
    finally:
        wx.EndBusyCursor()
コード例 #10
0
def handle_uncaught_exception_wx(t, v, tb):

    _log.debug('unhandled exception caught:', exc_info=(t, v, tb))

    if __handle_access_violation(t, v, tb):
        return

    if __handle_ctrl_c(t, v, tb):
        return

    if __handle_exceptions_on_shutdown(t, v, tb):
        return

    if __ignore_dead_objects_from_async(t, v, tb):
        return

    if __handle_import_error(t, v, tb):
        return

    if __handle_wxgtk_assertion(t, v, tb):
        return

    # other exceptions
    _cfg = gmCfgINI.gmCfgData()
    if _cfg.get(option='debug') is False:
        _log.error('enabling debug mode')
        _cfg.set_option(option='debug', value=True)
        root_logger = logging.getLogger()
        root_logger.setLevel(logging.DEBUG)
        _log.debug('unhandled exception caught:', exc_info=(t, v, tb))

    if __handle_lost_db_connection(t, v, tb):
        return

    gmLog2.log_stack_trace(None, t, v, tb)

    # only do this here or else we can invalidate the stack trace
    # by Windows throwing an exception ... |-(
    # careful: MSW does reference counting on Begin/End* :-(
    wx.EndBusyCursor()

    name = os.path.basename(_logfile_name)
    name, ext = os.path.splitext(name)
    new_name = os.path.expanduser(
        os.path.join(
            '~', '.local', 'gnumed', 'error_logs', '%s_%s%s' %
            (name, pyDT.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'), ext)))

    dlg = cUnhandledExceptionDlg(None,
                                 -1,
                                 exception=(t, v, tb),
                                 logfile=new_name)
    dlg.ShowModal()
    comment = dlg._TCTRL_comment.GetValue()
    dlg.DestroyLater()
    if (comment is not None) and (comment.strip() != ''):
        _log.error('user comment: %s', comment.strip())

    _log.warning('syncing log file for backup to [%s]', new_name)
    gmLog2.flush()
    # keep a copy around
    shutil.copy2(_logfile_name, new_name)