Rev 6: Use a RegistryOption rather than 2 plain Option objects. (suggested by Aaron) in http://bzr.arbash-meinel.com/plugins/x_bit
John Arbash Meinel
john at arbash-meinel.com
Wed Mar 28 20:32:06 BST 2007
At http://bzr.arbash-meinel.com/plugins/x_bit
------------------------------------------------------------
revno: 6
revision-id: john at arbash-meinel.com-20070328193205-6yr0qle4uyh5dvvh
parent: john at arbash-meinel.com-20070328191454-1jhr1ttjfeukrept
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: x_bit
timestamp: Wed 2007-03-28 14:32:05 -0500
message:
Use a RegistryOption rather than 2 plain Option objects. (suggested by Aaron)
modified:
__init__.py __init__.py-20060516204016-5be79f11e31f2cb7
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-03-28 19:14:54 +0000
+++ b/__init__.py 2007-03-28 19:32:05 +0000
@@ -14,7 +14,7 @@
)
from bzrlib.builtins import tree_files
from bzrlib.commands import Command, register_command
-from bzrlib.option import Option
+from bzrlib.option import Option, RegistryOption
class cmd_x_bit(Command):
@@ -23,23 +23,24 @@
# If we can't print the filename exactly, that is okay.
encoding_type = 'replace'
takes_args = ['files+']
- takes_options = [Option('set', help='set x-bit for file'),
- Option('clear', help='clear x-bit for file'),
+ takes_options = [RegistryOption.from_kwargs('executable',
+ value_switches=True, enum_switch=False,
+ set="set x-bit for file",
+ clear="clear x-bit for file"),
]
- def run(self, files_list, set=False, clear=False):
+ def run(self, files_list, executable=None):
from bzrlib.workingtree import WorkingTree
- if not set and not clear:
- raise errors.BzrCommandError(
- 'You must supply either --set or --clear')
- if set and clear:
- raise errors.BzrCommandError(
- 'You cannot supply both --set and --clear')
- # At this point 'set' will always be the desired value. Because if
- # 'set' is true, then the execute bit should be set, if it is False,
- # that means 'clear' must be True, which means the executable bit
- # should be False.
+ if executable is None:
+ raise errors.BzrCommandError('you must supply one of'
+ ' --set or --clear')
+ if executable == 'set':
+ executable = True
+ else:
+ assert executable == 'clear', \
+ 'Invalid value for executable: %s' % (executable,)
+ executable = False
tree, relpaths = builtins.tree_files(files_list)
# TreeTransform will grab a lock_tree_write()
@@ -61,11 +62,11 @@
x = tree.is_executable(fid)
- if x != set:
+ if x != executable:
trans_id = tt.trans_id_tree_path(fname)
- tt.set_executability(set, trans_id)
+ tt.set_executability(executable, trans_id)
self.outf.write("File %s => x-bit: %r\n"
- % (fname, set,))
+ % (fname, executable,))
finally:
tt.apply()
More information about the bazaar-commits
mailing list