/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to backend/info.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-07-06 17:08:45 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060706170845-da015b629f5876a4
2006-07-06  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * I'm not dead :)
    * backend/errors.py: added some exceptions related to fileops.move()
    * backend/fileops.py: implemented move()
    * backend/info_helper.py: added diff_helper()
    * backend/info.py: implemented diff()

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
from errors import (NotBranchError)
25
25
 
26
 
def nick(branch, nickname=None):
27
 
    """ Get or set nickname.
28
 
    
29
 
    :param branch: path to the branch
30
 
    
31
 
    :param nickname: if specified, the nickname will be set
32
 
    
33
 
    :return: nickname
34
 
    """
35
 
    try:
36
 
        branch = Branch.open_containing(branch)[0]
37
 
    except errors.NotBranchError:
38
 
        raise NotBranchError
39
 
    
40
 
    if nickname is not None:
41
 
        branch.nick = nickname
42
 
 
43
 
    return branch.nick    
44
 
 
45
 
def revno(branch):
46
 
    """ Get current revision number for specified branch
47
 
    
48
 
    :param branch: path to the branch
49
 
    
50
 
    :return: revision number
51
 
    """
52
 
    try:
53
 
        revno = Branch.open_containing(branch)[0].revno()
54
 
    except errors.NotBranchError:
55
 
        raise NotBranchError
56
 
    else:
57
 
        return revno
58
 
 
59
 
def version():
60
 
    """ Get version information from bzr
61
 
    
62
 
    :return: bzrlib version
63
 
    """
64
 
    return bzrlib.__version__
65
 
 
66
 
def whoami(branch=None, email=False):
67
 
    """ Get user's data (name and email address)
68
 
    
69
 
    :param branch: if specified, the user's data will be looked up in the branch's config
70
 
    
71
 
    :param email: if True, only the email address will be returned
72
 
    
73
 
    :return: user info (only email address if email is True)
74
 
    """
 
26
def diff(revision=None, file_list=None, diff_options=None, prefix=None):
 
27
    """ Save the diff into a temporary file.
 
28
    
 
29
    :param revision: a list of revisions (one or two elements)
 
30
    
 
31
    :param file_list: list of files you want to diff
 
32
    
 
33
    :param diff_options: external diff options
 
34
    
 
35
    :param prefix: 0 - p0, 1 - p1, or specify prefixes in the form of old/:new/
 
36
    
 
37
    :return: path to the temporary file which contains the diff output
 
38
    """
 
39
    from tempfile import mkstemp
 
40
    
 
41
    from bzrlib.builtins import internal_tree_files
 
42
    from bzrlib.diff import show_diff_trees
75
43
    from bzrlib.workingtree import WorkingTree
76
44
    
77
 
    if branch is not None:
78
 
        try:
79
 
            b = WorkingTree.open_containing(u'.')[0].branch
80
 
            config = bzrlib.config.BranchConfig(b)
81
 
        except NotBranchError:
82
 
            config = bzrlib.config.GlobalConfig()
83
 
    else:
84
 
        config = bzrlib.config.GlobalConfig()
85
 
        
86
 
    if email:
87
 
        return config.user_email()
88
 
    else:
89
 
        return config.username()
 
45
    from info_helper import diff_helper
 
46
 
 
47
    if (prefix is None) or (prefix == '0'):
 
48
        # diff -p0 format
 
49
        old_label = ''
 
50
        new_label = ''
 
51
    elif prefix == '1':
 
52
        old_label = 'old/'
 
53
        new_label = 'new/'
 
54
    else:
 
55
        if not ':' in prefix:
 
56
            raise errors.BzrError("--diff-prefix expects two values separated by a colon")
 
57
        old_label, new_label = prefix.split(":")
 
58
    
 
59
    try:
 
60
        tree1, file_list = internal_tree_files(file_list)
 
61
        tree2 = None
 
62
        b = None
 
63
        b2 = None
 
64
    except errors.FileInWrongBranch:
 
65
        if len(file_list) != 2:
 
66
            raise errors.BzrCommandError("Files are in different branches")
 
67
 
 
68
        tree1, file1 = WorkingTree.open_containing(file_list[0])
 
69
        tree2, file2 = WorkingTree.open_containing(file_list[1])
 
70
    
 
71
        if file1 != "" or file2 != "":
 
72
            # FIXME diff those two files. rbc 20051123
 
73
            raise errors.BzrCommandError("Files are in different branches")
 
74
    
 
75
        file_list = None
 
76
    
 
77
    tmpfile = mkstemp(prefix='olive_')
 
78
    tmpfp = open(tmpfile[1], 'w')
 
79
    
 
80
    if revision is not None:
 
81
        if tree2 is not None:
 
82
            raise errors.BzrCommandError("Can't specify -r with two branches")
 
83
    
 
84
        if (len(revision) == 1) or (revision[1].spec is None):
 
85
            ret = diff_helper(tree1, file_list, diff_options,
 
86
                                   revision[0], 
 
87
                                   old_label=old_label, new_label=new_label,
 
88
                                   output=tmpfp)
 
89
        elif len(revision) == 2:
 
90
            ret = diff_helper(tree1, file_list, diff_options,
 
91
                                   revision[0], revision[1],
 
92
                                   old_label=old_label, new_label=new_label,
 
93
                                   output=tmpfp)
 
94
        else:
 
95
            raise errors.BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
 
96
    else:
 
97
        if tree2 is not None:
 
98
            ret = show_diff_trees(tree1, tree2, tmpfp, 
 
99
                                   specific_files=file_list,
 
100
                                   external_diff_options=diff_options,
 
101
                                   old_label=old_label, new_label=new_label)
 
102
        else:
 
103
            ret = diff_helper(tree1, file_list, diff_options,
 
104
                                   old_label=old_label, new_label=new_label,
 
105
                                   output=tmpfp)
 
106
    
 
107
    tmpfp.close()
 
108
    
 
109
    if ret == 0:
 
110
        return False
 
111
    else:
 
112
        return tmpfile[1]
90
113
 
91
114
def info(location):
92
115
    """ Get info about branch, working tree, and repository
192
215
        return
193
216
    except errors.NoRepositoryPresent:
194
217
        pass
 
218
 
 
219
def nick(branch, nickname=None):
 
220
    """ Get or set nickname.
 
221
    
 
222
    :param branch: path to the branch
 
223
    
 
224
    :param nickname: if specified, the nickname will be set
 
225
    
 
226
    :return: nickname
 
227
    """
 
228
    try:
 
229
        branch = Branch.open_containing(branch)[0]
 
230
    except errors.NotBranchError:
 
231
        raise NotBranchError
 
232
    
 
233
    if nickname is not None:
 
234
        branch.nick = nickname
 
235
 
 
236
    return branch.nick    
 
237
 
 
238
def revno(branch):
 
239
    """ Get current revision number for specified branch
 
240
    
 
241
    :param branch: path to the branch
 
242
    
 
243
    :return: revision number
 
244
    """
 
245
    try:
 
246
        revno = Branch.open_containing(branch)[0].revno()
 
247
    except errors.NotBranchError:
 
248
        raise NotBranchError
 
249
    else:
 
250
        return revno
 
251
 
 
252
def version():
 
253
    """ Get version information from bzr
 
254
    
 
255
    :return: bzrlib version
 
256
    """
 
257
    return bzrlib.__version__
 
258
 
 
259
def whoami(branch=None, email=False):
 
260
    """ Get user's data (name and email address)
 
261
    
 
262
    :param branch: if specified, the user's data will be looked up in the branch's config
 
263
    
 
264
    :param email: if True, only the email address will be returned
 
265
    
 
266
    :return: user info (only email address if email is True)
 
267
    """
 
268
    from bzrlib.workingtree import WorkingTree
 
269
    
 
270
    if branch is not None:
 
271
        try:
 
272
            b = WorkingTree.open_containing(u'.')[0].branch
 
273
            config = bzrlib.config.BranchConfig(b)
 
274
        except NotBranchError:
 
275
            config = bzrlib.config.GlobalConfig()
 
276
    else:
 
277
        config = bzrlib.config.GlobalConfig()
 
278
        
 
279
    if email:
 
280
        return config.user_email()
 
281
    else:
 
282
        return config.username()