-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnightlies_regen.php
107 lines (91 loc) · 2.95 KB
/
nightlies_regen.php
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
<?php
require_once("Nightlies.php");
require_once("user.php");
require_once("memcache.php");
lockNightlies_R();
$nightlies=$memcache->get("nightlies");
$nightTimer=$memcache->get("nightlies.timer");
//echo "acquiring read lock\n";
if($nightlies && tryLockNightlies_W()) {
//echo "checking for expired cache\n";
if(!$nightTimer) {
echo "expired cache detected\n";
unlockNightlies_R();
echo "regenerating... ";
$output=renderNightlies($oauth);
lockNightlies_R();
$memcache->delete("nightlies", 0);
$memcache->add("nightlies", $output);
setNightlies_Timer();
}
unlockNightlies_W();
unlockNightlies_R();
//echo "complete, locks cleared.\n";
} elseif(!$nightlies){
echo "trying to generate first cache\n";
if(tryLockNightlies_W()) {
echo "acquired write lock on nightlies cache... ";
unlockNightlies_R();
echo "gave up read lock\n";
$output=renderNightlies($oauth);
lockNightlies_R();
echo "writing cache... ";
$memcache->add("nightlies", $output);
setNightlies_Timer();
unlockNightlies_W();
unlockNightlies_R();
echo "done, locks cleared\n";
}
}
unlockNightlies_R();
//echo "gave up read lock\n";
// heavy lifting
function renderNightlies($oauth) {
$errorcode="";
$nightlies=new Nightlies();
$template=file_get_contents('/var/www/nightlies-with/nightlies.mustache');
$users=User::fetchUsers();
$nightlies->total_users=count($users);
foreach($users as $user) {
if($user->uid == 25204506) continue;
if($user->uid == 22575230) continue;
$oauth_tokens=array('token' => $user->token, 'token_secret' => $user->token_secret);
$oauth->setToken($oauth_tokens);
$dropbox = new Dropbox_API($oauth);
//$dropbox->createFolder("Public/android-x86");
try {
$androidDir=null;
$androidDir=$dropbox->getMetaData("Public/" . $nightlies->contentPath);
$acct=$dropbox->getAccountInfo();
$uid=$acct['uid'];
if($androidDir['contents'] == NULL) {
throw new Exception("NOUPLOAD");
}
foreach($androidDir['contents'] as $content) {
$dPath=preg_replace("/^\/Public\//", "", $content['path']);
$dFile=basename($dPath);
array_push($user->files, Array('content' => $dFile));
}
array_push($nightlies->users, $user);
} catch (Dropbox_Exception_NotFound $e) {
// echo "New user must create <code>Public/android-x86/</code>...\n";
// echo "<em>$user->display_name</em>, please read the documentation!<br/>\n";
} catch (OAuthException $e) {
$errorcode.="Luser has de-authed the app...\n";
$errorcode.="$user->display_name, goodbye :-(<br/>\n";
} catch (Exception $e) {
if($e->getMessage()=="NOUPLOAD") {
// echo "New user must upload something...\n";
// echo "<em>$user->display_name</em>, please make a build!<br/>\n";
}
else {
// echo "Unhandled exception!<br/>\n";
}
}
}
$nightlies->errorcode=$errorcode;
$nightlies->hash=hash("sha256",serialize($nightlies));
$output=$nightlies->render($template);
return $output;
}
?>