1
1
<?php
2
2
3
+ use Composer \InstalledVersions ;
3
4
4
5
$ installed = array ();
5
6
@@ -89,6 +90,35 @@ function InstallLibrary($libraryname, $version , $blank = true){
89
90
$ tmp = `$ callstring `;
90
91
}
91
92
93
+ function InstallLibraryByID ($ libraryID , $ blank = true ){
94
+ global $ Settings ;
95
+ global $ installed ;
96
+ //echo "Already installed :::::::::::::" . PHP_EOL;
97
+ //print_r($installed);
98
+ if ($ blank ) {
99
+ ClearAllLibraries ();
100
+ $ installed = array ();
101
+ }
102
+ $ libdata = DB ::queryFirstRow ("Select * from libs WHERE id = %i " ,$ libraryID );
103
+ $ version = $ libdata ['lib_version ' ];
104
+ $ libraryname = $ libdata ['lib_name ' ];
105
+
106
+ if (in_array ($ libraryname ,$ installed )) return true ;
107
+ echo "Installing $ libraryname " . PHP_EOL ;
108
+ $ installed [] = $ libraryname ;
109
+
110
+ //print_r($libdata);
111
+ //$callstring = "cd " . $Settings['arduino_library'] . " && git clone -b '$version' " . str_replace('https://github.com/','[email protected] :',$libdata['lib_url']) . " 2>/dev/null";
112
+ //echo $callstring . PHP_EOL;
113
+ GitCheckoutTag ($ libdata ['lib_url ' ],$ version );
114
+ if (strlen ($ libdata ['lib_depends ' ])> 0 ){
115
+ $ libs = explode (", " ,$ libdata ['lib_depends ' ]);
116
+ for ($ x =0 ; $ x < count ($ libs );$ x ++){
117
+ if (!in_array ($ libs [$ x ],$ installed )) InstallNewestLibrary ($ libs [$ x ],false );
118
+ }
119
+ }
120
+ //$tmp = `$callstring`;
121
+ }
92
122
93
123
function InstallNewestLibrary ($ libraryname ,$ IsNewInstall = true ){
94
124
$ libdata = DB ::queryFirstRow ("Select * from libs WHERE lib_name LIKE %s ORDER by lib_version DESC " ,$ libraryname );
@@ -115,8 +145,9 @@ function TestLibraryByID($id, $platform = 1){
115
145
$ offDyn = $ Settings ['platformdata ' ][$ platform ]['platform_emptydyn ' ] ;
116
146
global $ Settings ;
117
147
$ libdata = DB ::queryFirstRow ("Select * from libs WHERE id LIKE %i " ,$ id );
118
- InstallNewestLibrary ($ libdata ['lib_name ' ],true );
119
148
if (!is_array ($ libdata )) return false ;
149
+ // InstallNewestLibrary($libdata['lib_name'],true);
150
+ InstallLibraryByID ($ id );
120
151
$ examples = FindLibraryExamples ($ libdata ['lib_url ' ]);
121
152
$ completed = false ;
122
153
$ minPS = 999999999 ;
@@ -182,11 +213,11 @@ function fIsLibraryChecked($liburl){
182
213
return false ;
183
214
}
184
215
185
- function fGetLibraryDetails ($ liburl ){
216
+ function fAddNewLibrary ($ liburl ){
186
217
global $ Settings ;
187
- // ClearAllLibraries();
188
- // $callstring = "cd " . $Settings['arduino_library'] . " && git clone " . str_replace('https://github.com/','[email protected] :',$liburl) . " 2>/dev/null";
189
- // $tmp = `$callstring`;
218
+ ClearAllLibraries ();
219
+ $ callstring =
"cd " .
$ Settings[
'arduino_library ' ] .
" && git clone " .
str_replace (
'https://github.com/ ' ,
'[email protected] : ' ,
$ liburl) .
" 2>/dev/null " ;
220
+ $ tmp = `$ callstring `;
190
221
$ callstring = "find " . $ Settings ['arduino_library ' ] . " -name 'library.properties' " ;
191
222
//echo $callstring . PHP_EOL;
192
223
$ pf = str_replace ("\n" ,"" ,`$ callstring `);
@@ -201,36 +232,75 @@ function fGetLibraryDetails($liburl){
201
232
$ pf = array ();
202
233
203
234
for ($ y =0 ;$ y < count ($ tags );$ y ++){
204
- $ pf [$ tag ] = "" ;
235
+ $ pf [$ tags [ $ y ] ] = "" ;
205
236
}
206
237
207
238
for ($ x = 0 ; $ x < count ($ lines );$ x ++){
208
239
$ line = $ lines [$ x ];
209
-
240
+ echo " ---> " . $ line . PHP_EOL ;
210
241
for ($ y =0 ;$ y < count ($ tags );$ y ++){
211
242
$ tag = $ tags [$ y ];
212
243
if (strlen ($ line )>strlen ($ tag ."= " )) if (substr ($ line ,0 ,strlen ($ tag . "= " )) == $ tag . "= " ) $ pf [$ tag ] = explode ("= " ,$ line ,2 )[1 ];
213
-
244
+
214
245
}
215
246
216
247
print_r (substr ($ line ,0 ,strlen ("version= " )));
217
248
echo PHP_EOL ;
218
249
}
219
250
251
+ $ snippet ['architectures ' ] = array ();
252
+ if (strlen ($ pf ['architectures ' ])> 0 ){
253
+ $ snippet ['architectures ' ] = explode (", " ,$ pf ['architectures ' ]);
254
+ }
255
+
256
+ $ depends = "" ;
257
+ $ snippet ['depends ' ] = array ();
258
+ if (strlen ($ pf ['depends ' ])> 0 ){
259
+
260
+ $ snippet ['depends ' ] = explode (", " ,$ pf ['depends ' ]);
261
+ for ($ x = 0 ; $ x < count ($ snippet ['depends ' ]);$ x ++){
262
+ $ snippet ['depends ' ][$ x ] = trim ($ snippet ['depends ' ][$ x ]);
263
+ }
264
+ }
265
+ $ depends = implode (", " ,$ snippet ['depends ' ]);
266
+
267
+
268
+ $ data = [
269
+ 'lib_name ' => $ pf ['name ' ],
270
+ 'lib_url ' => $ liburl ,
271
+ 'lib_version ' => $ pf ['version ' ],
272
+ 'lib_depends ' => $ depends ,
273
+ 'lib_architectures ' => ", " . implode (", " ,$ snippet ['architectures ' ]) . ", " ,
274
+ 'lib_sentence ' => $ pf ['sentence ' ],
275
+ //'pf' => $pf
276
+ ];
277
+ db::insertIgnore ("libs " ,$ data );
278
+ $ pf = $ data ;
220
279
221
280
}
281
+
282
+
222
283
return $ pf ;
223
284
}
224
285
225
286
226
- /*
227
- version=1.7.0
228
- author=Arduino
229
- maintainer=Arduino <[email protected] >
230
- sentence=Enables communication between the Linux processor and the microcontroller. For Arduino Yún, Yún Shield and TRE only.
231
- paragraph=The Bridge library features: access to the shared storage, run and manage Linux processes, open a remote console, access to the Linux file system, including the SD card, establish HTTP clients or servers.
232
- category=Communication
233
- url=http://www.arduino.cc/en/Reference/YunBridgeLibrary
234
- architectures=*
235
-
236
- */
287
+ function GitCheckoutTag ($ liburl ,$ version ){
288
+ global $ Settings ;
289
+ $ callstring =
"cd " .
$ Settings[
'arduino_library ' ] .
" && git clone " .
str_replace (
'https://github.com/ ' ,
'[email protected] : ' ,
$ liburl) .
" 2>/dev/null " ;
290
+ $ bnc = "basename ' $ liburl' '.git' " ;
291
+ $ bn = str_replace ("\n" ,"" , `$ bnc `);
292
+ $ tmp = `$ callstring `;
293
+ $ callstring = "cd ' " . $ Settings ['arduino_library ' ] . $ bn . "' && git tag " ;
294
+ $ tmp = `$ callstring `;
295
+ $ finaltag ="" ;
296
+ $ tags = explode ("\n" ,$ tmp );
297
+ for ($ x =0 ;$ x <count ($ tags );$ x ++){
298
+ if ( $ version == $ tags [$ x ] || "v " . $ version == $ tags [$ x ] || "v. " . $ version == $ tags [$ x ] ){
299
+ $ finaltag = $ tags [$ x ];
300
+ }
301
+ }
302
+ if (strlen ($ finaltag )>0 ){
303
+ $ callstring = "cd ' " . $ Settings ['arduino_library ' ] . $ bn . "' && git checkout 'tags/ $ finaltag' " ;
304
+ $ tmp = `$ callstring `;
305
+ }
306
+ }
0 commit comments