|
1
by Alexander Belchenko
initial interface to x-bit command |
1 |
#!/usr/bin/python
|
2 |
||
3 |
"""Control x-bit inside of bzr inventory
|
|
4 |
Primarily intended to use on win32 platform.
|
|
5 |
||
6 |
Written by Alexander Belchenko, 2006
|
|
7 |
"""
|
|
8 |
||
9 |
from bzrlib.commands import Command, register_command |
|
|
2
by Alexander Belchenko
realisation with set/clear |
10 |
from bzrlib.option import Option |
|
1
by Alexander Belchenko
initial interface to x-bit command |
11 |
|
12 |
||
13 |
class cmd_x_bit(Command): |
|
14 |
"""Control executable bit of particular file(s)"""
|
|
15 |
||
16 |
takes_args = ['files+'] |
|
|
2
by Alexander Belchenko
realisation with set/clear |
17 |
takes_options = [Option('set', help='set x-bit for file'), |
18 |
Option('clear', help='clear x-bit for file'), |
|
19 |
]
|
|
|
1
by Alexander Belchenko
initial interface to x-bit command |
20 |
|
|
2
by Alexander Belchenko
realisation with set/clear |
21 |
def run(self, files_list, set=False, clear=False): |
22 |
from bzrlib.workingtree import WorkingTree |
|
23 |
||
24 |
tree = WorkingTree.open_containing(files_list[0])[0] |
|
|
4
by Alexander Belchenko
compatibility with bzr 0.15 (WT4): before work with tree we need to explicitly lock it |
25 |
if set != clear: |
26 |
tree.lock_tree_write() |
|
27 |
else: |
|
28 |
tree.lock_read() |
|
29 |
try: |
|
30 |
inv = tree.read_working_inventory() |
|
31 |
f_inv_changed = False |
|
32 |
||
33 |
for f in files_list: |
|
34 |
fid = inv.path2id(tree.relpath(f)) |
|
35 |
if fid is None: |
|
36 |
print "File", f, "is not versioned" |
|
37 |
continue
|
|
38 |
||
39 |
inv_entry = inv[fid] |
|
40 |
if inv_entry.kind != 'file': |
|
41 |
print "Path", f, "is not a file" |
|
42 |
continue
|
|
43 |
||
44 |
x = inv_entry.executable |
|
45 |
if set != clear: |
|
46 |
if set and not x: |
|
47 |
inv_entry.executable = True |
|
48 |
f_inv_changed = True |
|
49 |
elif clear and x: |
|
50 |
inv_entry.executable = False |
|
51 |
f_inv_changed = True |
|
52 |
print "File", f, "=> x-bit: %r" % inv_entry.executable |
|
53 |
||
54 |
if f_inv_changed: |
|
55 |
tree._write_inventory(inv) |
|
56 |
finally: |
|
57 |
tree.unlock() |
|
|
2
by Alexander Belchenko
realisation with set/clear |
58 |
#/class cmd_x_bit
|
|
1
by Alexander Belchenko
initial interface to x-bit command |
59 |
|
60 |
||
61 |
register_command(cmd_x_bit) |