-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gitx.pm
226 lines (166 loc) · 5.05 KB
/
Gitx.pm
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/perl
# $Id$
#
# WEB INTERFACE and Controll application for an headless squeezelite
# installation.
#
# Best used with Squeezelite-R2
# (https://github.com/marcoc1712/squeezelite/releases)
#
# Copyright 2016 Marco Curti, marcoc1712 at gmail dot com.
# Please visit www.marcoc1712.it
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License,
# version 3.
#
# 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.
#
################################################################################
package Gitx; #can't Git->new()...
use strict;
use warnings;
use utf8;
use File::Basename;
use Cwd;
sub new{
my $class = shift;
my $status = shift;
my $self = bless {
_status => $status,
_utils => Utils->new($status),
_settings => Settings->new(),
}, $class;
return $self;
}
sub getStatus{
my $self = shift;
return $self->{_status};
}
sub getUtils{
my $self = shift;
return $self->{_utils};
}
sub getSettings{
my $self = shift;
return $self->{_settings};
}
sub getFalconHome{
my $self = shift;
return $self->getSettings()->{FALCON_HOME};
}
sub getGitUser{
my $self = shift;
return $self->getSettings()->{GIT_USER};
}
sub getGitMail{
my $self = shift;
return $self->getSettings()->{GIT_MAIL};
}
################################################################################
# tobe overidden
#
sub isInstalled{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub install{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub upgrade{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
sub uninstall{
my $self = shift;
$self->getStatus()->record('',5, "not implemented yet",'');
return 0;
}
################################################################################
#privates
#
sub gitConfigureUser{
my $self = shift;
my $dir = $self->getFalconHome();
chdir $dir;
if (! getcwd eq $dir){
$self->getStatus()->record("chdir ".$dir,7, "can't move into directory",getcwd);
return undef;
}
my $user= $self->getGitUser();
my $command = qq(git config user.name $user);
my ($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record($command,7, $err,(join '\n', @answ));
return undef;
}
$self->getStatus()->record($command,1, $err ? $err : 'done',(join '\n', @answ));
return 1;
}
sub gitConfigureMail{
my $self = shift;
my $dir = $self->getFalconHome();
chdir $dir;
if (! getcwd eq $dir){
$self->getStatus()->record("chdir ".$dir,7, "can't move into directory",getcwd);
return undef;
}
my $mail= $self->getGitMail();
my $command = qq(git config user.email $mail);
my ($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record($command,7, $err,(join '\n', @answ));
return undef;
}
$self->getStatus()->record($command,1, $err ? $err : 'done',(join '\n', @answ));
return 1;
}
sub gitClone{
my $self = shift;
my $www= $self->getSettings()->{WWW_DIRECTORY};
chdir $www;
if (! getcwd eq $www){
$self->getStatus()->record(' chdir '.$www,7, "can't move into directory",'');
return undef;
}
my $command = $self->getSettings()->{GIT_CLONE_STRING};
my ($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record('git clone',7, $err,(join '\n', @answ));
return undef;
}
$self->getStatus()->record('git clone',3, $err ? $err : 'done',(join '\n', @answ));
return 1;
}
sub gitPull{
my $self = shift;
my $falconHome= $self->getSettings()->{FALCON_HOME};
chdir $falconHome;
if (! cwd eq $falconHome){
$self->getStatus()->record(' chdir '.$falconHome,7, "can't move into directory",'');
return undef;
}
my $command = 'git stash';
my ($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record($command,7, $err,(join '\n', @answ));
return undef;
}
$self->getStatus()->record($command,3, $err ? $err : 'done',(join '\n', @answ));
$command = 'git pull';
($err, @answ)= $self->getUtils()->executeCommand($command);
if ($err){
$self->getStatus()->record($command,7, $err,(join '\n', @answ));
return undef;
}
$self->getStatus()->record($command,3, $err ? $err : 'done',(join '\n', @answ));
return 1;
}
1;