Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/webapp-config:master commit in: WebappConfig/, doc/
Date: Fri, 29 Mar 2013 23:11:04
Message-Id: 1364598600.a1e489227f090025610d08e4d2a43faa7e4cf80e.blueness@gentoo
1 commit: a1e489227f090025610d08e4d2a43faa7e4cf80e
2 Author: Devan Franchini <twitch153 <AT> hotmail <DOT> com>
3 AuthorDate: Fri Mar 29 03:16:53 2013 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Fri Mar 29 23:10:00 2013 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=a1e48922
7
8 WebappConfig/{config,worker}.py: add option to copy files
9
10 This adds an option to copy the webapp files rather than hardlink
11 them even if they are on the same filesystem. While this takes
12 up more disk space, it allows one to modify different instances
13 of webapp installations without affecting other instances.
14
15 X-Gentoo-Bug: 231482
16 X-Gentoo-Bug-URL: https://bugs.gentoo.org/231482
17 Signed-off-by: Anthony G. Basile <blueness <AT> gentoo.org>
18
19 ---
20 WebappConfig/config.py | 16 ++++++++++++++++
21 WebappConfig/worker.py | 36 ++++++++++++++++++++++++++++++++++++
22 doc/webapp-config.8.xml | 18 ++++++++++++++----
23 3 files changed, 66 insertions(+), 4 deletions(-)
24
25 diff --git a/WebappConfig/config.py b/WebappConfig/config.py
26 index 37fb0e2..fd106c5 100644
27 --- a/WebappConfig/config.py
28 +++ b/WebappConfig/config.py
29 @@ -490,6 +490,13 @@ class Config:
30 ' when creating virtual files. <NOTE>: some pack'
31 'ages will not work if you use this option')
32
33 + group.add_option('--cp',
34 + '--copy',
35 + action='store_true',
36 + help = 'Directly copy the webapp files from'
37 + ' the /usr/share/webapps/ directory when installing'
38 + ' the webapp.')
39 +
40 group.add_option('--virtual-files',
41 '--vf',
42 type = 'choice',
43 @@ -845,6 +852,7 @@ class Config:
44 'user' : 'vhost_config_uid',
45 'group' : 'vhost_config_gid',
46 'soft' : 'g_soft',
47 + 'copy' : 'g_copy',
48 'virtual_files': 'vhost_config_virtual_files',
49 'default_dirs' : 'vhost_config_default_dirs',
50 'pretend' : 'g_pretend',
51 @@ -990,6 +998,14 @@ class Config:
52 OUT.debug('Selecting soft links' , 7)
53
54 self.config.set('USER', 'g_link_type', 'soft')
55 +
56 + elif (self.config.has_option('USER', 'g_copy') and
57 + self.config.getboolean('USER', 'g_copy')):
58 +
59 + OUT.debug('Selecting copying of links', 7)
60 +
61 + self.config.set('USER', 'g_link_type', 'clone')
62 +
63 else:
64
65 OUT.debug('Selecting hard links' , 7)
66
67 diff --git a/WebappConfig/worker.py b/WebappConfig/worker.py
68 index 07a2f1a..250f068 100644
69 --- a/WebappConfig/worker.py
70 +++ b/WebappConfig/worker.py
71 @@ -495,6 +495,10 @@ class WebappAdd:
72 OUT.debug('Trying to softlink', 8)
73
74 if not self.__p:
75 + if self.__v:
76 + print("\n>>> SOFTLINKING FILE: ")
77 + print(">>> Source: " + src_name +
78 + "\n>>> Destination: " + dst_name + "\n")
79 os.symlink(src_name, dst_name)
80
81 my_contenttype = 'sym'
82 @@ -504,12 +508,35 @@ class WebappAdd:
83 if self.__v:
84 OUT.warn('Failed to softlink (' + str(e) + ')')
85
86 + elif self.__link_type == 'clone':
87 + try:
88 +
89 + OUT.debug('Trying to copy files directly', 8)
90 +
91 + if not self.__p:
92 + if self.__v:
93 + print("\n>>> COPYING FILE: ")
94 + print(">>> Source: " + src_name +
95 + "\n>>> Destination: " + dst_name + "\n")
96 + shutil.copy(src_name, dst_name)
97 +
98 + my_contenttype = 'file'
99 +
100 + except Exception as e:
101 +
102 + if self.__v:
103 + OUT.warn('Failed to copy (' + str(e) + ')')
104 +
105 elif os.path.islink(src_name):
106 try:
107
108 OUT.debug('Trying to copy symlink', 8)
109
110 if not self.__p:
111 + if self.__v:
112 + print("\n>>> SYMLINK COPY: ")
113 + print(">>> Source: " + src_name +
114 + "\n>>> Destination: " + dst_name + "\n")
115 os.symlink(os.readlink(src_name), dst_name)
116
117 my_contenttype = 'sym'
118 @@ -525,6 +552,10 @@ class WebappAdd:
119 OUT.debug('Trying to hardlink', 8)
120
121 if not self.__p:
122 + if self.__v:
123 + print("\n>>> HARDLINKING FILE: ")
124 + print(">>> Source: " + src_name +
125 + "\n>>> Destination: " + dst_name + "\n")
126 os.link(src_name, dst_name)
127
128 my_contenttype = 'file'
129 @@ -535,7 +566,12 @@ class WebappAdd:
130 OUT.warn('Failed to hardlink (' + str(e) + ')')
131
132 if not my_contenttype:
133 +
134 if not self.__p:
135 + if self.__v:
136 + print("\n>>> COPYING FILE: ")
137 + print(">>> Source: " + src_name +
138 + "\n>>> Destination: " + dst_name + "\n")
139 shutil.copy(src_name, dst_name)
140 my_contenttype = 'file'
141
142
143 diff --git a/doc/webapp-config.8.xml b/doc/webapp-config.8.xml
144 index e3f2c08..dda1ec4 100644
145 --- a/doc/webapp-config.8.xml
146 +++ b/doc/webapp-config.8.xml
147 @@ -68,6 +68,7 @@
148 <arg choice="opt">
149 <option>-dghusDE</option>
150 <option>--soft</option>
151 + <option>--copy</option>
152 <option>--secure</option>
153 </arg>
154 <arg choice="req">
155 @@ -217,14 +218,15 @@
156 </refsect2>
157
158 <refsect2>
159 - <title>Hard Linking vs Soft Linking</title>
160 + <title>File Copying Options</title>
161 <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>
162 <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>
163 - <para>There are two ways to get around the hard link problem.</para>
164 + <para>There are three ways to get around the hard link problem.</para>
165 <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>
166 <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>
167 - <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>
168 + <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>
169 <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>
170 + <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>
171 </refsect2>
172
173 <refsect2>
174 @@ -465,12 +467,20 @@
175 <varlistentry>
176 <term><option>--soft</option></term>
177 <listitem>
178 - <para>Use this option to create the virtual copy using symbolic links instead of hard links.</para>
179 + <para>Use this option to create the virtual copy using symbolic links.</para>
180 <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>
181 </listitem>
182 </varlistentry>
183
184 <varlistentry>
185 + <term><option>--cp</option></term>
186 + <term><option>--copy</option></term>
187 + <listitem>
188 + <para>Use this option to create the virtual copy by copying the files from the <filename>/usr/share/webapps/</filename> directories.</para>
189 + <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>
190 + </varlistentry>
191 +
192 + <varlistentry>
193 <term><option>--secure</option></term>
194 <listitem>
195 <para>Use this option to install into the <filename>htdocs-secure</filename> directory rather than into the <filename>htdocs</filename> directory.</para>