Implemented creating of target files during creating symlinks

Change-Id: Ibeecbcf9210dcec219478dba3f5dadc901e4e99c
diff --git a/rsync_remote.py b/rsync_remote.py
index a877c46..91aeebb 100644
--- a/rsync_remote.py
+++ b/rsync_remote.py
@@ -113,14 +113,22 @@
         self.logger.info('Creating directory "{}"'.format(dirname))
         return self._do_rsync(source=source, opts=opts)
 
-    def symlink(self, symlink, target):
+    def symlink(self, symlink, target, create_target_file=True):
         '''Creates symlink targeted to target'''
-        # TODO: implement creating of file <symlink>.symlink on remote with
-        # info about link target, something like this
-        # <symlink> = <target>
-        source = self.tmp.get_symlink_to(target)
+
         symlink = self.url.a_file(symlink)
+        if create_target_file is True:
+            infofile = self.url.a_file('{}.target.txt'.format(symlink))
+            source = self.tmp.get_file(content='{}'.format(target))
+            temp_dir = self.tmp.last_temp_dir
+            self.rmfile(infofile)
+            self.logger.info('Creating informaion file "{}"'.format(infofile))
+            self._do_rsync(source=source, dest=infofile)
+        else:
+            temp_dir = self.tmp.get_temp_dir()
+
         opts = "-l"
+        source = self.tmp.get_symlink_to(target, temp_dir=temp_dir)
         self.rmfile(symlink)
         self.logger.info('Creating symlink "{}" -> "{}"'
                          ''.format(symlink, target))
diff --git a/tempfiles.py b/tempfiles.py
index ac7dbca..c3ffb3d 100644
--- a/tempfiles.py
+++ b/tempfiles.py
@@ -41,6 +41,10 @@
         self.logger.debug(msg)
         return temp_dir
 
+    @property
+    def last_temp_dir(self):
+        return self._temp_dirs[-1]
+
     def create_subdirs(self, subdirs, temp_dir):
         if not os.path.isdir(temp_dir):
             temp_dir = self.get_temp_dir()
@@ -66,3 +70,12 @@
         self.logger.debug('Creates temporary symlink "{} -> {}"'
                           ''.format(linkname, target))
         return linkname
+
+    def get_file(self, content='', temp_dir=None):
+        if temp_dir is None:
+            temp_dir = self.get_temp_dir()
+        filename = tempfile.mktemp(dir=temp_dir)
+        with open(filename, 'w') as outfile:
+            outfile.write(content)
+        self.logger.debug('Creates temporary file "{}"'.format(filename))
+        return filename