diff options
author | 2013-03-28 23:16:53 -0400 | |
---|---|---|
committer | 2013-03-29 19:10:00 -0400 | |
commit | a1e489227f090025610d08e4d2a43faa7e4cf80e (patch) | |
tree | e09a8ec76dfc9f2174607e65744a2becdf610220 | |
parent | WebappConfig/wrapper.py: do not use portage.root to retrive $ROOT (diff) | |
download | webapp-config-a1e489227f090025610d08e4d2a43faa7e4cf80e.tar.gz webapp-config-a1e489227f090025610d08e4d2a43faa7e4cf80e.tar.bz2 webapp-config-a1e489227f090025610d08e4d2a43faa7e4cf80e.zip |
WebappConfig/{config,worker}.py: add option to copy files
This adds an option to copy the webapp files rather than hardlink
them even if they are on the same filesystem. While this takes
up more disk space, it allows one to modify different instances
of webapp installations without affecting other instances.
X-Gentoo-Bug: 231482
X-Gentoo-Bug-URL: https://bugs.gentoo.org/231482
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | WebappConfig/config.py | 16 | ||||
-rw-r--r-- | WebappConfig/worker.py | 36 | ||||
-rw-r--r-- | doc/webapp-config.8.xml | 18 |
3 files changed, 66 insertions, 4 deletions
diff --git a/WebappConfig/config.py b/WebappConfig/config.py index 37fb0e2..fd106c5 100644 --- a/WebappConfig/config.py +++ b/WebappConfig/config.py @@ -490,6 +490,13 @@ class Config: ' when creating virtual files. <NOTE>: some pack' 'ages will not work if you use this option') + group.add_option('--cp', + '--copy', + action='store_true', + help = 'Directly copy the webapp files from' + ' the /usr/share/webapps/ directory when installing' + ' the webapp.') + group.add_option('--virtual-files', '--vf', type = 'choice', @@ -845,6 +852,7 @@ class Config: 'user' : 'vhost_config_uid', 'group' : 'vhost_config_gid', 'soft' : 'g_soft', + 'copy' : 'g_copy', 'virtual_files': 'vhost_config_virtual_files', 'default_dirs' : 'vhost_config_default_dirs', 'pretend' : 'g_pretend', @@ -990,6 +998,14 @@ class Config: OUT.debug('Selecting soft links' , 7) self.config.set('USER', 'g_link_type', 'soft') + + elif (self.config.has_option('USER', 'g_copy') and + self.config.getboolean('USER', 'g_copy')): + + OUT.debug('Selecting copying of links', 7) + + self.config.set('USER', 'g_link_type', 'clone') + else: OUT.debug('Selecting hard links' , 7) diff --git a/WebappConfig/worker.py b/WebappConfig/worker.py index 07a2f1a..250f068 100644 --- a/WebappConfig/worker.py +++ b/WebappConfig/worker.py @@ -495,6 +495,10 @@ class WebappAdd: OUT.debug('Trying to softlink', 8) if not self.__p: + if self.__v: + print("\n>>> SOFTLINKING FILE: ") + print(">>> Source: " + src_name + + "\n>>> Destination: " + dst_name + "\n") os.symlink(src_name, dst_name) my_contenttype = 'sym' @@ -504,12 +508,35 @@ class WebappAdd: if self.__v: OUT.warn('Failed to softlink (' + str(e) + ')') + elif self.__link_type == 'clone': + try: + + OUT.debug('Trying to copy files directly', 8) + + if not self.__p: + if self.__v: + print("\n>>> COPYING FILE: ") + print(">>> Source: " + src_name + + "\n>>> Destination: " + dst_name + "\n") + shutil.copy(src_name, dst_name) + + my_contenttype = 'file' + + except Exception as e: + + if self.__v: + OUT.warn('Failed to copy (' + str(e) + ')') + elif os.path.islink(src_name): try: OUT.debug('Trying to copy symlink', 8) if not self.__p: + if self.__v: + print("\n>>> SYMLINK COPY: ") + print(">>> Source: " + src_name + + "\n>>> Destination: " + dst_name + "\n") os.symlink(os.readlink(src_name), dst_name) my_contenttype = 'sym' @@ -525,6 +552,10 @@ class WebappAdd: OUT.debug('Trying to hardlink', 8) if not self.__p: + if self.__v: + print("\n>>> HARDLINKING FILE: ") + print(">>> Source: " + src_name + + "\n>>> Destination: " + dst_name + "\n") os.link(src_name, dst_name) my_contenttype = 'file' @@ -535,7 +566,12 @@ class WebappAdd: OUT.warn('Failed to hardlink (' + str(e) + ')') if not my_contenttype: + if not self.__p: + if self.__v: + print("\n>>> COPYING FILE: ") + print(">>> Source: " + src_name + + "\n>>> Destination: " + dst_name + "\n") shutil.copy(src_name, dst_name) my_contenttype = 'file' diff --git a/doc/webapp-config.8.xml b/doc/webapp-config.8.xml index e3f2c08..dda1ec4 100644 --- a/doc/webapp-config.8.xml +++ b/doc/webapp-config.8.xml @@ -68,6 +68,7 @@ <arg choice="opt"> <option>-dghusDE</option> <option>--soft</option> + <option>--copy</option> <option>--secure</option> </arg> <arg choice="req"> @@ -217,14 +218,15 @@ </refsect2> <refsect2> - <title>Hard Linking vs Soft Linking</title> + <title>File Copying Options</title> <para>A <glossterm>virtual copy</glossterm> is built mostly by creating hard links to files under <filename>/usr/share/webapps</filename>. If a hard link cannot be created, the file is copied from <filename>/usr/share/webapps</filename> instead.</para> <para>Hard links can only be created to files on the same filesystem. If you keep <filename>/usr/share/webapps</filename> and <filename>/var/www</filename> on different filesystems, <command>webapp-config</command> cannot use hard links, and will be forced to copy the files instead.</para> - <para>There are two ways to get around the hard link problem.</para> + <para>There are three ways to get around the hard link problem.</para> <para>The easiest way is to make <filename>/usr/share/webapps</filename> a symlink to a directory under <filename>/var/www</filename>. For most people, this will ensure that everything is on the same filesystem.</para> <para>However, if you keep the websites you host on separate filesystems (like I do), then <command>webapp-config</command> is never going to be able to hard-link files for you.</para> - <para>You can choose to use the <option>--soft</option> command-line switch instead. This switch tells <command>webapp-config</command> to create symbolic links instead of hard links. Symbolic links work across filesystems.</para> + <para>As an alternative you can choose to use the <option>--soft</option> command-line switch. This switch tells <command>webapp-config</command> to create symbolic links instead of hard links. Symbolic links work across filesystems.</para> <para>The problem with using symbolic links is that some packages do not work when the virtual copy is made from symbolic links. Many users - and system administrators alas - have also complained that they find directories full of symbolic links confusing. For these reasons, symbolic links are not used by default in <command>webapp-config</command> any more.</para> + <para>You may also choose the <option>--copy</option> command-line switch. This particular switch tells <command>webapp-config</command> to directly copy the files from <filename>/usr/share/webapps/</filename> instead of hard links. Copying directly works across filesystems with the drawback of using more space but if you are going to use it across file systems you may want this instead of symbolic links, as this means that the files in <filename>/usr/share/webapps/</filename> will not be touched when the files in the location of your virtualhost are altered.</para> </refsect2> <refsect2> @@ -465,12 +467,20 @@ <varlistentry> <term><option>--soft</option></term> <listitem> - <para>Use this option to create the virtual copy using symbolic links instead of hard links.</para> + <para>Use this option to create the virtual copy using symbolic links.</para> <para>You may find this option useful if <filename>/usr/share/webapps</filename> is on a different filesystem to your htdocs directories. However, it has been discovered that some packages do not work with this option, which is why it is no longer the default behaviour. You are always better off making <filename>/usr/share/webapps</filename> a symlink to a directory on the same filesystem as your htdocs directories.</para> </listitem> </varlistentry> <varlistentry> + <term><option>--cp</option></term> + <term><option>--copy</option></term> + <listitem> + <para>Use this option to create the virtual copy by copying the files from the <filename>/usr/share/webapps/</filename> directories.</para> + <para>This option is useful if you want to copy the files directly from <filename>/usr/share/webapps/</filename> to your virtual host in /var/www without the use of softlinks, or hardlinks. Be aware that because this is a direct copying of files it will prove to take up more space on your filesystem as opposed to the other two options since you are duplicating the webapp.</para> + </varlistentry> + + <varlistentry> <term><option>--secure</option></term> <listitem> <para>Use this option to install into the <filename>htdocs-secure</filename> directory rather than into the <filename>htdocs</filename> directory.</para> |