Skip to content

Commit 332b9ff

Browse files
committed
change how packages are fetched on ubuntu;
1 parent 765c5e0 commit 332b9ff

4 files changed

Lines changed: 114 additions & 25 deletions

File tree

serverStatus/static/serverStatus/serverStatus.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
789789
$scope.currentPage = 1;
790790
$scope.recordsToShow = 10;
791791

792-
$scope.fetchPackages = function () {
792+
$scope.fetchPackages = function (type = 'installed') {
793793
$scope.cyberpanelLoading = false;
794794

795795
var config = {
@@ -800,7 +800,8 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
800800

801801
var data = {
802802
page: $scope.currentPage,
803-
recordsToShow: $scope.recordsToShow
803+
recordsToShow: $scope.recordsToShow,
804+
type: type
804805
};
805806

806807
dataurl = "/serverstatus/fetchPackages";
@@ -833,6 +834,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
833834

834835

835836
};
837+
$scope.fetchPackages('upgrade');
836838

837839
$scope.killProcess = function (pid) {
838840

serverStatus/templates/serverStatus/packageManager.html

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,80 @@ <h2>{% trans "Package Manager" %}</h2>
2222

2323
<div class="example-box-wrapper">
2424
<ul class="nav-responsive nav nav-tabs">
25-
<li class="active"><a href="#tab4" data-toggle="tab">Updates</a></li>
25+
<li class="active"><a ng-click="fetchPackages('upgrade')" href="#tab4" data-toggle="tab">Updates</a></li>
2626
<li><a ng-click="fetchPackages()" href="#tab6" data-toggle="tab">All Packages</a></li>
2727
<li><a href="#tab7" data-toggle="tab">Settings</a></li>
2828
<img ng-hide="cyberpanelLoading"
2929
src="{% static 'images/loading.gif' %}">
3030
</ul>
3131
<div class="tab-content">
3232
<div class="tab-pane active" id="tab4">
33-
<p>Howdy, I'm in Section 4.</p>
33+
<a style="float: left ; margin-bottom: 2%"
34+
class="btn btn-border btn-alt border-azure btn-link font-azure" href="#"
35+
title=""><span>Total Upgradeable Packages: {$ totalPackages $}</span></a>
36+
<a style="float: left; margin-bottom: 2%; margin-left: 2%"
37+
class="btn btn-border btn-alt border-blue-alt btn-link font-blue-alt" href="#"
38+
title=""><span>Fetched Packages: {$ fetchedPackages $}</span></a>
39+
<div class="col-sm-10"
40+
style="padding: 0px; box-shadow: 0px 0px 1px 0px #888888; margin-bottom: 2%">
41+
<input placeholder="Search..."
42+
ng-model="packSearch" name="packSearch" type="text"
43+
class="form-control" required>
44+
</div>
45+
<div class="col-sm-2">
46+
<div class="form-group">
47+
<select ng-model="recordsToShow" ng-change="fetchPackages('upgrade')"
48+
class="form-control" id="example-select">
49+
<option>10</option>
50+
<option>50</option>
51+
<option>100</option>
52+
<option>500</option>
53+
</select>
54+
</div>
55+
</div>
56+
<div class="form-group">
57+
<div class="col-sm-12">
58+
59+
<table class="table" style="margin: 0px; padding: 0px">
60+
<thead>
61+
<tr>
62+
<th>{% trans "Package" %}</th>
63+
<th>{% trans "Version" %}</th>
64+
<th>{% trans "Upgrade" %}</th>
65+
<th>{% trans "Actions" %}</th>
66+
</tr>
67+
</thead>
68+
<tbody>
69+
<tr ng-repeat="record in allPackages | filter:packSearch">
70+
<td ng-bind="record.package"></td>
71+
<td ng-bind="record.version"></td>
72+
<td ng-bind="record.upgrade"></td>
73+
<td><a style="float: left ; margin-bottom: 2%"
74+
class="btn btn-border btn-alt border-azure btn-link font-azure"
75+
href="#"
76+
title=""><span>Upgrade</span></a></td>
77+
</tr>
78+
</tbody>
79+
</table>
80+
</div>
81+
</div>
82+
<div style="margin-top: 2%" class="row">
83+
<div style="margin-top: 2%" class="col-md-12">
84+
<div class="row">
85+
<div class="col-md-9">
86+
</div>
87+
<div class="col-md-3">
88+
<div class="form-group">
89+
<select ng-model="currentPage" class="form-control"
90+
ng-change="fetchPackages('upgrade')">
91+
<option ng-repeat="page in pagination">{$ $index + 1 $}
92+
</option>
93+
</select>
94+
</div>
95+
</div>
96+
</div> <!-- end row -->
97+
</div>
98+
</div>
3499
</div>
35100
<div class="tab-pane" id="tab6">
36101
<a style="float: left ; margin-bottom: 2%"
@@ -63,17 +128,20 @@ <h2>{% trans "Package Manager" %}</h2>
63128
<thead>
64129
<tr>
65130
<th>{% trans "Package" %}</th>
66-
<th>{% trans "Description" %}</th>
67-
<th>{% trans "Status" %}</th>
68131
<th>{% trans "Version" %}</th>
132+
<th>{% trans "Upgrade" %}</th>
133+
<th>{% trans "Actions" %}</th>
69134
</tr>
70135
</thead>
71136
<tbody>
72137
<tr ng-repeat="record in allPackages | filter:packSearch">
73138
<td ng-bind="record.package"></td>
74-
<td ng-bind="record.description"></td>
75-
<td ng-bind="record.status"></td>
76139
<td ng-bind="record.version"></td>
140+
<td ng-bind="record.upgrade"></td>
141+
<td><a style="float: left ; margin-bottom: 2%"
142+
class="btn btn-border btn-alt border-azure btn-link font-azure"
143+
href="#"
144+
title=""><span>Upgrade</span></a></td>
77145
</tr>
78146
</tbody>
79147
</table>

serverStatus/views.py

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -728,18 +728,25 @@ def fetchPackages(request):
728728
data = json.loads(request.body)
729729
page = int(str(data['page']).rstrip('\n'))
730730
recordsToShow = int(data['recordsToShow'])
731-
732-
packageInformation = '/home/cyberpanel/OSPackages'
733-
f = open(packageInformation, "w")
731+
type = data['type']
734732

735733
if ProcessUtilities.decideDistro() == ProcessUtilities.ubuntu:
736-
command = 'dpkg-query -f \'{"status":"${db:Status-Abbrev}","package":"${binary:Package}","version":"${Version}","description":"${binary:Summary}"}\n\' -W'
737-
subprocess.call(shlex.split(command), stdout=f)
734+
command = 'apt list --installed'
735+
packages = ProcessUtilities.outputExecutioner(command).split('\n')
736+
packages = packages[4:]
737+
738+
upgradePackages = []
739+
740+
if type == 'upgrade':
741+
for pack in packages:
742+
if pack.find('upgradable') > -1:
743+
upgradePackages.append(pack)
738744

739-
packages = ProcessUtilities.outputExecutioner('cat %s' % (packageInformation)).split('\n')
745+
packages = upgradePackages
740746

741-
# if os.path.exists(ProcessUtilities.debugPath):
742-
# logging.CyberCPLogFileWriter.writeToFile('All packages: %s' % (str(packages)))
747+
748+
#if os.path.exists(ProcessUtilities.debugPath):
749+
# logging.CyberCPLogFileWriter.writeToFile('All packages: %s' % (str(packages)))
743750

744751
from s3Backups.s3Backups import S3Backups
745752

@@ -751,20 +758,30 @@ def fetchPackages(request):
751758
checker = 0
752759
counter = 0
753760

754-
# if os.path.exists(ProcessUtilities.debugPath):
755-
# logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages)))
761+
if os.path.exists(ProcessUtilities.debugPath):
762+
logging.CyberCPLogFileWriter.writeToFile('Final packages: %s' % (str(finalPackages)))
763+
756764
import re
757765
for items in finalPackages:
758-
items = re.sub(r'("[\s\w]*)"([\s\w])*"([\s\w]*)',r"\1\2\3", items)
759766
try:
767+
nowSplitted = items.split('now')
768+
769+
upgrade = 'Not Needed'
770+
771+
if nowSplitted[1].split(' ')[3].find('upgradable') > -1:
772+
upgrade = nowSplitted[1].split(' ')[3]
773+
774+
dic = {'package': nowSplitted[0].split('/')[0], 'version': '%s %s' % (nowSplitted[1].split(' ')[1], nowSplitted[1].split(' ')[2]), 'upgrade': upgrade}
775+
760776
counter = counter + 1
761777
if checker == 0:
762-
json_data = json_data + items
778+
json_data = json_data + json.dumps(dic)
763779
checker = 1
764780
else:
765-
json_data = json_data + ',' + items
766-
except:
767-
logging.CyberCPLogFileWriter.writeToFile(items)
781+
json_data = json_data + ',' + json.dumps(dic)
782+
783+
except BaseException as msg:
784+
logging.CyberCPLogFileWriter.writeToFile('[ERROR] %s. [fetchPackages:773]' % (str(msg)))
768785

769786
json_data = json_data + ']'
770787

static/serverStatus/serverStatus.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
789789
$scope.currentPage = 1;
790790
$scope.recordsToShow = 10;
791791

792-
$scope.fetchPackages = function () {
792+
$scope.fetchPackages = function (type = 'installed') {
793793
$scope.cyberpanelLoading = false;
794794

795795
var config = {
@@ -800,7 +800,8 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
800800

801801
var data = {
802802
page: $scope.currentPage,
803-
recordsToShow: $scope.recordsToShow
803+
recordsToShow: $scope.recordsToShow,
804+
type: type
804805
};
805806

806807
dataurl = "/serverstatus/fetchPackages";
@@ -833,6 +834,7 @@ app.controller('listOSPackages', function ($scope, $http, $timeout) {
833834

834835

835836
};
837+
$scope.fetchPackages('upgrade');
836838

837839
$scope.killProcess = function (pid) {
838840

0 commit comments

Comments
 (0)