~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

Move doctest import to increase speed

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
import os
74
74
import sha
75
75
import time
76
 
import warnings
77
76
 
78
77
from bzrlib.trace import mutter
79
78
from bzrlib.errors import (WeaveError, WeaveFormatError, WeaveParentMismatch,
85
84
import bzrlib.errors as errors
86
85
from bzrlib.osutils import sha_strings
87
86
import bzrlib.patiencediff
88
 
from bzrlib.symbol_versioning import (deprecated_method,
89
 
        deprecated_function,
90
 
        zero_eight,
91
 
        )
 
87
from bzrlib.symbol_versioning import *
92
88
from bzrlib.tsort import topo_sort
93
89
from bzrlib.versionedfile import VersionedFile, InterVersionedFile
94
90
from bzrlib.weavefile import _read_weave_v5, write_weave_v5
639
635
 
640
636
    def annotate(self, version_id):
641
637
        if isinstance(version_id, int):
642
 
            warnings.warn('Weave.annotate(int) is deprecated. Please use version names'
 
638
            warn('Weave.annotate(int) is deprecated. Please use version names'
643
639
                 ' in all circumstances as of 0.8',
644
640
                 DeprecationWarning,
645
641
                 stacklevel=2
1243
1239
    from bzrlib.weavefile import read_weave
1244
1240
 
1245
1241
    wf = file(weave_file, 'rb')
1246
 
    w = read_weave(wf)
 
1242
    w = read_weave(wf, WeaveVersionedFile)
1247
1243
    # FIXME: doesn't work on pipes
1248
1244
    weave_size = wf.tell()
1249
1245
 
1423
1419
        raise ValueError('unknown command %r' % cmd)
1424
1420
    
1425
1421
 
 
1422
 
 
1423
def profile_main(argv):
 
1424
    import tempfile, hotshot, hotshot.stats
 
1425
 
 
1426
    prof_f = tempfile.NamedTemporaryFile()
 
1427
 
 
1428
    prof = hotshot.Profile(prof_f.name)
 
1429
 
 
1430
    ret = prof.runcall(main, argv)
 
1431
    prof.close()
 
1432
 
 
1433
    stats = hotshot.stats.load(prof_f.name)
 
1434
    #stats.strip_dirs()
 
1435
    stats.sort_stats('cumulative')
 
1436
    ## XXX: Might like to write to stderr or the trace file instead but
 
1437
    ## print_stats seems hardcoded to stdout
 
1438
    stats.print_stats(20)
 
1439
            
 
1440
    return ret
 
1441
 
 
1442
 
 
1443
def lsprofile_main(argv): 
 
1444
    from bzrlib.lsprof import profile
 
1445
    ret,stats = profile(main, argv)
 
1446
    stats.sort()
 
1447
    stats.pprint()
 
1448
    return ret
 
1449
 
 
1450
 
1426
1451
if __name__ == '__main__':
1427
1452
    import sys
1428
 
    sys.exit(main(sys.argv))
 
1453
    if '--profile' in sys.argv:
 
1454
        args = sys.argv[:]
 
1455
        args.remove('--profile')
 
1456
        sys.exit(profile_main(args))
 
1457
    elif '--lsprof' in sys.argv:
 
1458
        args = sys.argv[:]
 
1459
        args.remove('--lsprof')
 
1460
        sys.exit(lsprofile_main(args))
 
1461
    else:
 
1462
        sys.exit(main(sys.argv))
1429
1463
 
1430
1464
 
1431
1465
class InterWeave(InterVersionedFile):