mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 23:34:24 +01:00
#43 new: bsd base support
This commit is contained in:
@@ -10,10 +10,11 @@ import 'package:toolbox/data/model/app/shell_func.dart';
|
||||
import 'package:toolbox/data/model/docker/image.dart';
|
||||
import 'package:toolbox/data/model/docker/ps.dart';
|
||||
import 'package:toolbox/data/model/app/error.dart';
|
||||
import 'package:toolbox/data/res/server_cmd.dart';
|
||||
import 'package:toolbox/data/store/docker.dart';
|
||||
import 'package:toolbox/locator.dart';
|
||||
|
||||
import '../res/server_cmd.dart';
|
||||
|
||||
final _dockerNotFound = RegExp(r'command not found|Unknown command');
|
||||
final _versionReg = RegExp(r'(Version:)\s+([0-9]+\.[0-9]+\.[0-9]+)');
|
||||
// eg: `Docker Engine - Community`
|
||||
@@ -72,7 +73,7 @@ class DockerProvider extends ChangeNotifier {
|
||||
|
||||
// Check result segments count
|
||||
final segments = raw.split(seperator);
|
||||
if (segments.length != dockerCmds.length) {
|
||||
if (segments.length != DockerCmdType.values.length) {
|
||||
error = DockerErr(type: DockerErrType.segmentsNotMatch);
|
||||
_logger.warning('Docker segments not match: ${segments.length}');
|
||||
notifyListeners();
|
||||
@@ -119,28 +120,28 @@ class DockerProvider extends ChangeNotifier {
|
||||
}
|
||||
|
||||
// Parse docker stats
|
||||
final statsRaw = DockerCmdType.stats.find(segments);
|
||||
try {
|
||||
final statsLines = statsRaw.split('\n');
|
||||
statsLines.removeWhere((element) => element.isEmpty);
|
||||
if (statsLines.isNotEmpty) statsLines.removeAt(0);
|
||||
for (var item in items!) {
|
||||
final statsLine = statsLines.firstWhere(
|
||||
(element) => element.contains(item.containerId),
|
||||
orElse: () => '',
|
||||
);
|
||||
if (statsLine.isEmpty) continue;
|
||||
item.parseStats(statsLine);
|
||||
}
|
||||
} catch (e, trace) {
|
||||
error = DockerErr(
|
||||
type: DockerErrType.parseStats,
|
||||
message: '$statsRaw\n-\n$e',
|
||||
);
|
||||
_logger.warning('Parse docker stats: $statsRaw', e, trace);
|
||||
} finally {
|
||||
notifyListeners();
|
||||
}
|
||||
// final statsRaw = DockerCmdType.stats.find(segments);
|
||||
// try {
|
||||
// final statsLines = statsRaw.split('\n');
|
||||
// statsLines.removeWhere((element) => element.isEmpty);
|
||||
// if (statsLines.isNotEmpty) statsLines.removeAt(0);
|
||||
// for (var item in items!) {
|
||||
// final statsLine = statsLines.firstWhere(
|
||||
// (element) => element.contains(item.containerId),
|
||||
// orElse: () => '',
|
||||
// );
|
||||
// if (statsLine.isEmpty) continue;
|
||||
// item.parseStats(statsLine);
|
||||
// }
|
||||
// } catch (e, trace) {
|
||||
// error = DockerErr(
|
||||
// type: DockerErrType.parseStats,
|
||||
// message: '$statsRaw\n-\n$e',
|
||||
// );
|
||||
// _logger.warning('Parse docker stats: $statsRaw', e, trace);
|
||||
// } finally {
|
||||
// notifyListeners();
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> _onPwd(String event, StreamSink<Uint8List> stdin) async {
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:toolbox/data/model/app/shell_func.dart';
|
||||
import 'package:toolbox/data/model/server/system.dart';
|
||||
|
||||
import '../../core/extension/order.dart';
|
||||
import '../../core/extension/uint8list.dart';
|
||||
@@ -265,18 +266,28 @@ class ServerProvider extends ChangeNotifier {
|
||||
|
||||
final raw = await s.client?.run(AppShellFuncType.status.exec).string;
|
||||
final segments = raw?.split(seperator).map((e) => e.trim()).toList();
|
||||
if (raw == null ||
|
||||
raw.isEmpty ||
|
||||
segments == null ||
|
||||
segments.length != StatusCmdType.values.length) {
|
||||
if (raw == null || raw.isEmpty || segments == null || segments.isEmpty) {
|
||||
_limiter.inc(sid);
|
||||
s.status.failedInfo = 'Seperate segments failed, raw:\n$raw';
|
||||
_setServerState(s, ServerState.failed);
|
||||
return;
|
||||
}
|
||||
|
||||
final systemType = SystemType.parse(segments[0]);
|
||||
if (systemType == null || !systemType.isSegmentsLenMatch(segments.length)) {
|
||||
_limiter.inc(sid);
|
||||
s.status.failedInfo = 'Segments not match: ${segments.length}';
|
||||
_setServerState(s, ServerState.failed);
|
||||
return;
|
||||
}
|
||||
s.status.system = systemType;
|
||||
|
||||
try {
|
||||
final req = ServerStatusUpdateReq(s.status, segments);
|
||||
final req = ServerStatusUpdateReq(
|
||||
ss: s.status,
|
||||
segments: segments,
|
||||
system: systemType,
|
||||
);
|
||||
s.status = await compute(getStatus, req);
|
||||
} catch (e, trace) {
|
||||
_limiter.inc(sid);
|
||||
|
||||
Reference in New Issue
Block a user