~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/util.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-17 22:33:55 UTC
  • mfrom: (366 trunk)
  • mto: This revision was merged to the branch mainline in revision 367.
  • Revision ID: mnordhoff@mattnordhoff.com-20090617223355-i0bwf75e5o87kxr8
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
20
#
21
21
 
 
22
try:
 
23
    from xml.etree import ElementTree as ET
 
24
except ImportError:
 
25
    from elementtree import ElementTree as ET
 
26
 
 
27
from simpletal.simpleTALUtils import HTMLStructureCleaner
 
28
 
22
29
import base64
23
30
import cgi
24
31
import datetime
31
38
import os
32
39
import subprocess
33
40
 
34
 
try:
35
 
    from xml.etree import ElementTree as ET
36
 
except ImportError:
37
 
    from elementtree import ElementTree as ET
38
 
 
39
 
from simpletal.simpleTALUtils import HTMLStructureCleaner
40
 
 
41
41
log = logging.getLogger("loggerhead.controllers")
42
42
 
43
43
 
129
129
    return _wrap_with_date_time_title(date, _displaydate(date))
130
130
 
131
131
 
132
 
class Container(object):
 
132
class Container (object):
133
133
    """
134
134
    Convert a dict into an object with attributes.
135
135
    """
217
217
 
218
218
    return: the same value recieved if not empty, and a ' ' if it is.
219
219
    """
 
220
 
 
221
 
220
222
    if s is None:
221
223
        return ' '
222
224
    elif isinstance(s, int):
314
316
 
315
317
    out = str(base)
316
318
    if (base < 100) and (dot != 0):
317
 
        out += '.%d' % (dot,)
 
319
        out += '.%d' % (dot)
318
320
    if divisor == KILO:
319
321
        out += 'K'
320
322
    elif divisor == MEG:
382
384
    """
383
385
    # Is our root directory itself a branch?
384
386
    if is_root:
 
387
        if view == 'directory':
 
388
            directory = 'files'
385
389
        breadcrumbs = [{
386
390
            'dir_name': path,
387
391
            'path': '',
461
465
        now = time.time()
462
466
        msec = int(now * 1000) % 1000
463
467
        timestr = time.strftime('%Y%m%d%H%M%S',
464
 
                                time.localtime(now)) + ('%03d' % (msec,))
 
468
                                time.localtime(now)) + ('%03d' % msec)
465
469
        filename = f.__name__ + '-' + timestr + '.lsprof'
466
470
        cPickle.dump(stats, open(filename, 'w'), 2)
467
471
        return ret
533
537
    _reloader_environ_key = 'PYTHON_RELOADER_SHOULD_RUN'
534
538
 
535
539
    @classmethod
536
 
    def _turn_sigterm_into_systemexit(cls):
 
540
    def _turn_sigterm_into_systemexit(self):
537
541
        """
538
542
        Attempts to turn a SIGTERM exception into a SystemExit exception.
539
543
        """
547
551
        signal.signal(signal.SIGTERM, handle_term)
548
552
 
549
553
    @classmethod
550
 
    def is_installed(cls):
551
 
        return os.environ.get(cls._reloader_environ_key)
 
554
    def is_installed(self):
 
555
        return os.environ.get(self._reloader_environ_key)
552
556
 
553
557
    @classmethod
554
 
    def install(cls):
 
558
    def install(self):
555
559
        from paste import reloader
556
560
        reloader.install(int(1))
557
561
 
558
562
    @classmethod
559
 
    def restart_with_reloader(cls):
 
563
    def restart_with_reloader(self):
560
564
        """Based on restart_with_monitor from paste.script.serve."""
561
565
        print 'Starting subprocess with file monitor'
562
 
        while True:
 
566
        while 1:
563
567
            args = [sys.executable] + sys.argv
564
568
            new_environ = os.environ.copy()
565
 
            new_environ[cls._reloader_environ_key] = 'true'
 
569
            new_environ[self._reloader_environ_key] = 'true'
566
570
            proc = None
567
571
            try:
568
572
                try:
569
 
                    cls._turn_sigterm_into_systemexit()
 
573
                    self._turn_sigterm_into_systemexit()
570
574
                    proc = subprocess.Popen(args, env=new_environ)
571
575
                    exit_code = proc.wait()
572
576
                    proc = None
575
579
                    return 1
576
580
            finally:
577
581
                if (proc is not None
578
 
                    and getattr(os, 'kill', None) is not None):
 
582
                    and hasattr(os, 'kill')):
579
583
                    import signal
580
584
                    try:
581
585
                        os.kill(proc.pid, signal.SIGTERM)