/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/fileops.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-06-21 20:14:00 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-20060621201400-ef7ddfe95b6687a0
2006-06-20  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * backend/init.py: moved pull() to backend/update.py
    * backend/update.py: implemented update() and missing()
        
2006-06-19  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
        
    * backend/errors.py: renamed NoPushLocationKnown to NoLocationKnown
    * backend/init.py: implemented pull()

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
 
2
# Some parts of the code are:
 
3
# Copyright (C) 2005, 2006 by Canonical Ltd
 
4
 
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
 
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
 
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
import os
 
20
 
 
21
import bzrlib.errors as errors
 
22
 
 
23
from errors import (DirectoryAlreadyExists, NoFilesSpecified, NoMatchingFiles,
 
24
                    NotVersionedError)
 
25
 
 
26
def mkdir(directory):
 
27
    """ Create new versioned directory.
 
28
    
 
29
    :param directory: the full path to the directory to be created
 
30
    """
 
31
    from bzrlib.workingtree import WorkingTree
 
32
    
 
33
    try:
 
34
        os.mkdir(directory)
 
35
    except OSError, e:
 
36
        if e.errno == 17:
 
37
            raise DirectoryAlreadyExists(directory)
 
38
    else:
 
39
        wt, dd = WorkingTree.open_containing(directory)
 
40
        wt.add([dd])
 
41
 
 
42
def add(file_list):
 
43
    """ Add listed files to the branch. 
 
44
    
 
45
    :param file_list - list of files to be added (using full paths)
 
46
    
 
47
    :return: count of ignored files
 
48
    """
 
49
    import bzrlib.add
 
50
    
 
51
    added, ignored = bzrlib.add.smart_add(file_list)
 
52
    
 
53
    match_len = 0
 
54
    for glob, paths in ignored.items():
 
55
        match_len += len(paths)
 
56
    
 
57
    return match_len
 
58
 
 
59
def remove(file_list, new=False):
 
60
    """ Make selected files unversioned.
 
61
    
 
62
    :param file_list: list of files/directories to be removed
 
63
    
 
64
    :param new: if True, the 'added' files will be removed
 
65
    """
 
66
    from bzrlib.builtins import tree_files
 
67
    
 
68
    tree, file_list = tree_files(file_list)
 
69
    
 
70
    if new is False:
 
71
        if file_list is None:
 
72
            raise NoFilesSpecified
 
73
    else:
 
74
        from bzrlib.delta import compare_trees
 
75
        added = [compare_trees(tree.basis_tree(), tree,
 
76
                               specific_files=file_list).added]
 
77
        file_list = sorted([f[0] for f in added[0]], reverse=True)
 
78
        if len(file_list) == 0:
 
79
            raise NoMatchingFiles
 
80
    
 
81
    try:
 
82
        tree.remove(file_list)
 
83
    except errors.NotVersionedError:
 
84
        raise NotVersionedError
 
85