/[metamod]/trunk/virtualenv.pl
ViewVC logotype

Contents of /trunk/virtualenv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2862 - (show annotations) (download)
Mon Oct 26 14:39:01 2015 UTC (4 years, 9 months ago) by geira
File MIME type: text/plain
File size: 5251 byte(s)
tests now passing in precise again after hash order randomization fix
test output now in test/webrun instead of clobbering normal site directory

1 #!/usr/bin/perl -w
2
3 =begin LICENCE
4
5 ----------------------------------------------------------------------------
6 METAMOD - Web portal for metadata search and upload
7
8 Copyright (C) 2013 met.no
9
10 Contact information:
11 Norwegian Meteorological Institute
12 Box 43 Blindern
13 0313 OSLO
14 NORWAY
15 email: geir.aalberg@met.no
16
17 This file is part of METAMOD
18
19 METAMOD is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23
24 METAMOD is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with METAMOD; if not, write to the Free Software
31 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 ----------------------------------------------------------------------------
33
34 =end LICENCE
35
36 =cut
37
38 use strict;
39 use warnings;
40
41 use File::Path qw(mkpath);
42 #use File::Basename;
43 use FindBin qw($Bin);
44 use lib "$Bin/common/lib";
45 use Metamod::Config; # this depends only on core modules
46 use Pod::Usage;
47
48 my $config_dir = $ARGV[0] or pod2usage(1);
49 my $install_dir = $ARGV[1] || $config_dir;
50
51 if (!Metamod::Config->config_found($config_dir)){
52 die "Could not find the configuration on the command line or the in the environment";
53 }
54
55 my $config = Metamod::Config->new($config_dir, { nolog => 1 });
56
57 if (-f $install_dir) {
58 $install_dir = `dirname $install_dir`;
59 chomp $install_dir;
60 }
61
62 mkpath "$install_dir/bin";
63
64 open my $file, '>', "$install_dir/bin/activate";
65 while (<DATA>) {
66 s/\[==([A-Z0-9_]+)==\]/$config->get($1)/ge;
67 print $file $_;
68 #print $_;
69 }
70 close($file);
71
72 =head1 NAME
73
74 B<virtualenv.pl> - check METAMOD master_config
75
76 =head1 DESCRIPTION
77
78 Perl version of Python's virtualenv, modified to METAMOD environment.
79 This script will create a file ./bin/activate in your config directory
80 (or somewhere else if specified as the second parameter).
81
82 This file can later be sourced to set all necessary environment
83 variables like PATH, PERL5LIB and METAMOD_MASTER_CONFIG so you won't
84 have to repeat that for every shell command.
85
86 =head1 USAGE
87
88 $ virtualenv.pl <path_to_config_dir> [ <install_dir>]
89 $ source ./bin/activate
90 $ . ./bin/activate # short version
91 $ deactivate # unset environment
92
93 =head1 AUTHOR
94
95 Geir Aalberg, E<lt>geira@met.noE<gt>
96
97 Based on penv.pl (C) 2010 Joe Topjian. Used by permission.
98 L<http://terrarum.net/development/perl-virtual-environments.html>
99
100 =head1 LICENSE
101
102 Copyright (C) 2013 The Norwegian Meteorological Institute.
103
104 METAMOD is free software; you can redistribute it and/or modify
105 it under the terms of the GNU General Public License as published by
106 the Free Software Foundation; either version 2 of the License, or
107 (at your option) any later version.
108
109 =cut
110
111 __DATA__
112 # Create an environment for running METAMOD from the commandline.
113 # This is just a convenience for setting the correct lib paths and
114 # master config environment
115 #
116 # This file must be used with "source bin/activate" *from bash*
117 # you cannot run it directly
118 #
119 # Created by virtualenv.pl
120
121 deactivate () {
122 # reset old environment variables
123 if [ -n "$_OLD_VIRTUAL_PERL5LIB" ] ; then
124 export PERL5LIB="$_OLD_VIRTUAL_PERL5LIB"
125 else
126 unset PERL5LIB
127 fi
128 unset _OLD_VIRTUAL_PERL5LIB
129
130 # This should detect bash and zsh, which have a hash command that must
131 # be called to get it to forget past commands. Without forgetting
132 # past commands the $PATH changes we made may not be respected
133 if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
134 hash -r
135 fi
136
137 if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
138 PS1="$_OLD_VIRTUAL_PS1"
139 export PS1
140 unset _OLD_VIRTUAL_PS1
141 fi
142
143 if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
144 PATH="$_OLD_VIRTUAL_PATH"
145 export PATH
146 unset _OLD_VIRTUAL_PATH
147 fi
148
149 unset VIRTUAL_ENV
150 if [ ! "$1" = "nondestructive" ] ; then
151 # Self destruct!
152 unset -f deactivate
153 fi
154 }
155
156 # unset irrelevant variables
157 deactivate nondestructive
158
159 export METAMOD_MASTER_CONFIG=[==CONFIG_DIR==]
160
161 export _OLD_VIRTUAL_PATH="$PATH"
162 ROOT=[==INSTALLATION_DIR==]
163 PROMPT=`basename [==CONFIG_DIR==]`
164 export PATH=$PATH:"$ROOT:$ROOT/base/init":"$ROOT/base/userinit":"$ROOT/base/scripts":"$ROOT/common":"$ROOT/common/scripts":"$ROOT/catalyst/script:$ROOT/local/bin"
165
166 if [ -n "[==CATALYST_LIB==]" ]; then
167 export _OLD_VIRTUAL_PERL5LIB="$PERL5LIB"
168 export PERL5LIB=$PERL5LIB:"[==CATALYST_LIB==]"
169 fi
170
171 if [ -z "$VIRTUAL_ENV_DISABLE_PROMPT" ] ; then
172 _OLD_VIRTUAL_PS1="$PS1"
173 export PS1="\[\033[1;44m\]($PROMPT)\[\033[1;m\] $PS1"
174 fi
175
176 # This should detect bash and zsh, which have a hash command that must
177 # be called to get it to forget past commands. Without forgetting
178 # past commands the $PATH changes we made may not be respected
179 if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
180 hash -r
181 fi
182
183 if [ -d "[==CATALYST_LIB==]" ]; then
184 eval $(perl -I[==CATALYST_LIB==] -Mlocal::lib=[==CATALYST_LIB==])
185 fi

Properties

Name Value
svn:executable *

svn@met.no
ViewVC Help
Powered by ViewVC 1.1.5