Implemented get-target CLI command
Change-Id: I56fd0fcdbb4c554983d3aa251ab48802e684a3e1
diff --git a/setup.cfg b/setup.cfg
index 5e63e23..eb46ba6 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -54,6 +54,7 @@
push = trsync.cmd.cli:PushCmd
symlink = trsync.cmd.cli:SymlinkCmd
remove = trsync.cmd.cli:RemoveCmd
+ get-target = trsync.cmd.cli:GetTargetCmd
[global]
setup-hooks =
diff --git a/trsync/cmd/cli.py b/trsync/cmd/cli.py
index 4b555ef..d283f42 100644
--- a/trsync/cmd/cli.py
+++ b/trsync/cmd/cli.py
@@ -26,6 +26,7 @@
from trsync.objects import rsync_mirror
from trsync.objects import rsync_ops
+from trsync.objects import rsync_url
class PushCmd(command.Command):
@@ -270,6 +271,39 @@
sys.exit(exitcode)
+class GetTargetCmd(command.Command):
+ log = logging.getLogger(__name__)
+
+ def get_description(self):
+ return "Evaluate the target for specified symlink "\
+ "(optional recursively)"
+
+ def get_parser(self, prog_name):
+ parser = super(GetTargetCmd, self).get_parser(prog_name)
+
+ parser.add_argument('symlink_url',
+ help='Symlink url to resolve (supported by rsync)')
+ parser.add_argument('-r', '--recursive',
+ action='store_true',
+ required=False,
+ default=False,
+ help='It specified, the symlink will be resolved '
+ 'recursively (if the symlink targeted to other '
+ 'symlinks tree - they will be resolved too). '
+ 'Disabled by default.')
+ return parser
+
+ def take_action(self, parsed_args):
+ properties = vars(parsed_args)
+ symlink_url = properties.pop('symlink_url', None)
+ recursive = properties.pop('recursive', False)
+
+ url = rsync_url.RsyncUrl(symlink_url)
+ remote = rsync_ops.RsyncOps(url.root, **properties)
+ target = remote.symlink_target(url.path, recursive=recursive)
+ print(target)
+
+
class TRsyncApp(app.App):
log = logging.getLogger(__name__)