-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.pl
executable file
·141 lines (136 loc) · 3.72 KB
/
setup.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
#
# Copyright (C) 2000-2019 the YAMBO team
# http://www.yambo-code.eu
#
# Authors (see AUTHORS file for details): AM
#
# This file is distributed under the terms of the GNU
# General Public License. You can redistribute it and/or
# modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation;
# either version 2, or (at your option) any later version.
#
# This program is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330,Boston,
#
use lib ".";
#
use Getopt::Long;
use File::Find;
use File::Spec;
use File::Basename;
use Cwd 'abs_path';
#
# pwd
#
$pwd=abs_path();
#
# Options list
&GetOptions("help" => \$help,
"install:s" => \$install,
"clean" => \$clean,
"more" => \$more,
"list" => \$list) or die;
sub usage {
print <<EndOfUsage
Syntax: tutorials.pl <ARGS>
where <ARGS> must include at least one of:
-h This help
-list List the available tutorials
-install [TUTORIAL] Download & install the core databases. A specific [TUTORIAL] can be provided.
If empty all tutorials are downloaded.
-clean Clean the repository (remove all execution files)
-more Download more tutorials (in addition to the basic ones)
EndOfUsage
;
exit;
}
#
my $len= length($install);
if ($len eq 0) {$install="all"};
#
if($help or (not $install and not $list and not $clean)){ usage };
#
my $ONLINE_tutorials_files_location="educational/tutorials/files";
$main_dir=abs_path();
#
# CLEAN
#=======
if ($clean) {
system("git ls-files --others --exclude-standard | xargs rm -fr");
system("git clean -f -d");
}
#
# LIST
#======
if ($list or $install) {
if ($list) {print "\nAvailable local tutorials:\n\n"};
&TUTORIALS_list;
foreach $dir (@tutorials) {
undef $more_tut;
$N++;
$tgz=$dir.".tar.gz";
if (-f $dir."/.more") {$more_tut =1};
if ($list)
{
@dirs = ( "./$dir");
@files = ();
find( sub { push @files, $File::Find::name if /SAVE/ }, @dirs );
foreach $dirr (@files)
{
$SAVE_dir=$dirr;
$SAVE_dir =~ s/SAVE//g;
if (-f $SAVE_dir."/.AUTOMATIC") {$auto =1};
}
if (not $more_tut) {print " $N: $dir"};
if ( $more_tut) {print " $N: $dir (additional)"};
print "\n";
}
elsif ($install)
{
if ($more_tut and not $more ) {next};
$tutorial=$dir;
&NAME_it;
if ("${install}_DBs.tar" =~ "$DBs_tutorial_tar" or "$install" =~ "all") { &DOWNLOAD_it };
}
}
if ($install and -d "tutorials") {system("rmdir -p tutorials")};
}
print "\nDone.\n";
#
sub TUTORIALS_list
{
@tutorials;
foreach $dir (<*>) {
if (-d $dir and not ($dir =~ "archive" or $dir =~ /bin/ or $dir =~ /Pseudo/)){
push @tutorials, $dir;
}
}
}
#
sub NAME_it{
$DBs_tutorial_tar="${tutorial}_DBs.tar";
$DBs_tutorial_archive="${tutorial}_DBs.tar.gz";
}
#
sub DOWNLOAD_it
{
chdir("./archive");
system("rm -f ${DBs_tutorial_archive}");
system("wget media.yambo-code.eu/${ONLINE_tutorials_files_location}/${DBs_tutorial_archive}");
if (-f ${DBs_tutorial_archive} ){
system("gunzip ${DBs_tutorial_archive}");
chdir("$pwd");
system("tar xf archive/${DBs_tutorial_tar} ");
system("gzip archive/${DBs_tutorial_tar}");
}
chdir("$pwd");
}