예제 #1
0
    def pdoc(self, obj, oname='', formatter=None):
        """Print the docstring for any object.

        Optional:
        -formatter: a function to run the docstring through for specially
        formatted docstrings."""

        head = self.__head  # so that itpl can find it even if private
        ds = getdoc(obj)
        if formatter:
            ds = formatter(ds)
        if inspect.isclass(obj):
            init_ds = getdoc(obj.__init__)
            output = itpl('$head("Class Docstring:")\n'
                          '$indent(ds)\n'
                          '$head("Constructor Docstring"):\n'
                          '$indent(init_ds)')
        elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
                 and hasattr(obj,'__call__'):
            call_ds = getdoc(obj.__call__)
            if call_ds:
                output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
                              '$head("Calling Docstring:")\n$indent(call_ds)')
            else:
                output = ds
        else:
            output = ds
        if output is None:
            self.noinfo('documentation', oname)
            return
        page(output)
예제 #2
0
    def pdoc(self,obj,oname='',formatter = None):
        """Print the docstring for any object.

        Optional:
        -formatter: a function to run the docstring through for specially
        formatted docstrings."""

        head = self.__head  # so that itpl can find it even if private
        ds = getdoc(obj)
        if formatter:
            ds = formatter(ds)
        if inspect.isclass(obj):
            init_ds = getdoc(obj.__init__)
            output = itpl('$head("Class Docstring:")\n'
                          '$indent(ds)\n'
                          '$head("Constructor Docstring"):\n'
                          '$indent(init_ds)')
        elif (type(obj) is types.InstanceType or isinstance(obj,object)) \
                 and hasattr(obj,'__call__'):
            call_ds = getdoc(obj.__call__)
            if call_ds:
                output = itpl('$head("Class Docstring:")\n$indent(ds)\n'
                              '$head("Calling Docstring:")\n$indent(call_ds)')
            else:
                output = ds
        else:
            output = ds
        if output is None:
            self.noinfo('documentation',oname)
            return
        page(output)
예제 #3
0
    def __call__(self,etype, evalue, etb):
        """Handle an exception, call for compatible with sys.excepthook"""

        # Report tracebacks shouldn't use color in general (safer for users)
        color_scheme = 'NoColor'

        # Use this ONLY for developer debugging (keep commented out for release)
        #color_scheme = 'Linux'   # dbg
        
        try:
            rptdir = self.IP.rc.ipythondir
        except:
            rptdir = os.getcwd()
        if not os.path.isdir(rptdir):
            rptdir = os.getcwd()
        report_name = os.path.join(rptdir,self.crash_report_fname)
        # write the report filename into the instance dict so it can get
        # properly expanded out in the user message template
        self.crash_report_fname = report_name
        TBhandler = ultraTB.VerboseTB(color_scheme=color_scheme,
                                           long_header=1)
        traceback = TBhandler.text(etype,evalue,etb,context=31)

        # print traceback to screen
        if self.show_crash_traceback:
            print >> sys.stderr, traceback

        # and generate a complete report on disk
        try:
            report = open(report_name,'w')
        except:
            print >> sys.stderr, 'Could not create crash report on disk.'
            return

        # Inform user on stderr of what happened
        msg = itpl('\n'+'*'*70+'\n'+self.user_message_template)
        print >> sys.stderr, msg

        # Construct report on disk
        report.write(self.make_report(traceback))
        report.close()
        raw_input("Press enter to exit:")
예제 #4
0
    def __call__(self,etype, evalue, etb):

        # Report tracebacks shouldn't use color in general (safer for users)
        color_scheme = 'NoColor'

        # Use this ONLY for developer debugging (keep commented out for release)
        #color_scheme = 'Linux'   # dbg
        
        try:
            rptdir = self.IP.rc.ipythondir
        except:
            rptdir = os.getcwd()
        if not os.path.isdir(rptdir):
            rptdir = os.getcwd()
        self.report_name = os.path.join(rptdir,'IPython_crash_report.txt')
        self.TBhandler = ultraTB.VerboseTB(color_scheme=color_scheme,long_header=1)
        traceback = self.TBhandler.text(etype,evalue,etb,context=31)

        # print traceback to screen
        print >> sys.stderr, traceback

        # and generate a complete report on disk
        try:
            report = open(self.report_name,'w')
        except:
            print >> sys.stderr, 'Could not create crash report on disk.'
            return

        msg = itpl('\n'+'*'*70+'\n'
"""
Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the traceback above this text.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It was left in the file named:
\t'$self.report_name'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to $self.bug_contact at $self.mailto
with the subject 'IPython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' $self.mailto < $self.report_name

To ensure accurate tracking of this issue, please file a report about it at:
http://www.scipy.net/roundup/ipython  (IPython's online bug tracker).
""")
        print >> sys.stderr, msg

        sec_sep = '\n\n'+'*'*75+'\n\n'
        report.write('*'*75+'\n\n'+'IPython post-mortem report\n\n')
        report.write('IPython version: %s \n\n' % __version__)
        report.write('Platform info  : os.name -> %s, sys.platform -> %s' %
                     (os.name,sys.platform) )
        report.write(sec_sep+'Current user configuration structure:\n\n')
        report.write(pformat(self.IP.rc.dict()))
        report.write(sec_sep+'Crash traceback:\n\n' + traceback)
        try:
            report.write(sec_sep+"History of session input:")
            for line in self.IP.user_ns['_ih']:
                report.write(line)
            report.write('\n*** Last line of input (may not be in above history):\n')
            report.write(self.IP._last_input_line+'\n')
        except:
            pass
        report.close()
예제 #5
0
    try:
        execfile('bkprc.py')
    except IOError:
        print 'You need to provide a config file: bkp.py rcfile'
        sys.exit()

# make output dir if needed
outdir = os.path.expanduser(outdir)
try:
    os.makedirs(outdir)
except OSError:  # raised if dir already exists -> no need to make it
    pass

# build rsync command and call:
exclude = re.sub(r'([^\s].*?)(\s|$)',r'--exclude "\1"\2',exc_pats)
rsync = itpl('rsync $rsync_opts $exclude')

# the same can also be done with lists (keep it for reference):
#exclude = string.join(['--exclude "'+p+'"' for p in qw(exc_pats)])

# rsync takes -r as a flag, not 0/1 so translate:
rec_flag = {0:'',1:'-r'}

# loop over user specified directories calling rsync
for bakdir,rec in to_backup.items():
    bakdir = os.path.expanduser(bakdir)
    xsys(itpl('$rsync $rec_flag[rec] $bakdir $outdir'),
         debug=0,verbose=1,header='\n### ')

# final actions?
final()
예제 #6
0
    try:
        execfile('bkprc.py')
    except IOError:
        print 'You need to provide a config file: bkp.py rcfile'
        sys.exit()

# make output dir if needed
outdir = os.path.expanduser(outdir)
try:
    os.makedirs(outdir)
except OSError:  # raised if dir already exists -> no need to make it
    pass

# build rsync command and call:
exclude = re.sub(r'([^\s].*?)(\s|$)', r'--exclude "\1"\2', exc_pats)
rsync = itpl('rsync $rsync_opts $exclude')

# the same can also be done with lists (keep it for reference):
#exclude = string.join(['--exclude "'+p+'"' for p in qw(exc_pats)])

# rsync takes -r as a flag, not 0/1 so translate:
rec_flag = {0: '', 1: '-r'}

# loop over user specified directories calling rsync
for bakdir, rec in to_backup.items():
    bakdir = os.path.expanduser(bakdir)
    xsys(itpl('$rsync $rec_flag[rec] $bakdir $outdir'),
         debug=0,
         verbose=1,
         header='\n### ')