Skip to content

Commit

Permalink
now all works
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 committed Mar 21, 2020
1 parent 295a4ec commit e1fa38f
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 62 deletions.
File renamed without changes.
6 changes: 1 addition & 5 deletions lib/apps/nodejs.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import '../task.dart';
import '../node_utils.dart';
import './node_utils.dart';
import '../utils.dart';
import 'dart:io';
import 'package:event_bus/event_bus.dart';
import '../filesize.dart';
import 'dart:async';
import 'dart:isolate';

final String userHome =
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];


void runGetDirectorySize(SendPort sendPort) {
List<Directory> out = [];
filesInDirectoryWithDepth(Directory(userHome), FileSystemEntityType.directory, 0, 3,out);
Expand Down
68 changes: 41 additions & 27 deletions lib/apps/python.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import 'dart:io';
import '../utils.dart';
import '../filesize.dart';
import 'dart:convert';
import './python_utils.dart';
import 'dart:isolate';

void runGetDirectorySize(SendPort sendPort) {
var dir = filesInDirectoryWithDepth(
Directory(userHome), FileSystemEntityType.directory, 0, 3);
sendPort.send(dir);
}

class PythonTask extends Task {
String app = "python";
Expand All @@ -12,45 +20,51 @@ class PythonTask extends Task {
@override
scan() async {
// final String workon = Platform.environment["WORKON_HOME"];
var p = Process.start("/usr/bin/printenv", [r"WORKON_HOME"]);
p.then((process) {
process.stdout.transform(utf8.decoder).listen((workon) {
_scan(workon.trim());
});
}).catchError((e){
this.eventBus.fire(TaskData(this.app, e.toString()));
}

);
// _scan(workon.trim());
// var p = Process.start("printenv", [r"WORKON_HOME"]);
// p.then((process) {
// process.stdout.transform(utf8.decoder).listen((workon) {
// _scan(workon.trim());
// });
// }).catchError((e){
// this.eventBus.fire(TaskData(this.app, e.toString()));
// }

// );

ReceivePort receivePort = ReceivePort();
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort,
onExit: receivePort.sendPort);

receivePort.listen((data) {
_scan(data);
isolate.kill(priority: 0);
});
}

_scan(workon) async {
final days = new DateTime.now().subtract(new Duration(days: 90));
var dirs = await filesInDirectory(
Directory(workon), FileSystemEntityType.directory);
var dirs = await filesInDirectory(workon, FileSystemEntityType.directory);
int total = 0;

Stream.fromIterable(dirs)
.skipWhile((element) => element.statSync().accessed.isAfter(days))
.asyncMap(
(event) async => {"dir": event, "size": await directorySize(event)})
.listen((event) {
print(event);
this.cache.add(event["dir"]);
.asyncMap((event) async {
var size = await directorySize(event);
var data = {"dir": event, "size": size};
return data;
}).listen((event) {
this.cache.add(event);
this.eventBus.fire(TaskData(this.app, event["dir"].path.toString()));
total += event["size"];
},onError:(e){
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
this
.eventBus
.fire(TaskState(this.app, TaskStatus.done, TaskType.scan, total));
} ).onDone(() {
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
}).onDone(() {
if (total == 0) {
this.eventBus.fire(TaskData(this.app, "empty"));
} else {
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
}
this
.eventBus
.fire(TaskState(this.app, TaskStatus.done, TaskType.scan, total));
});
}


}
57 changes: 57 additions & 0 deletions lib/apps/python_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

import 'package:path/path.dart' as path;
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType;

filesInDirectoryWithDepth(Directory dir, FileSystemEntityType typ,
int currentLevel, int maxLevel) {
final days = new DateTime.now().subtract(new Duration(days: 90));
if ([
"Documents",
"Applications",
"Desktop",
"Movies",
"Music",
"Pictures",
"Public"
].indexOf(path.basename(dir.path)) !=
-1) {
return;
}

if (path.basename(dir.path) == ".virtualenvs" &&
dir.statSync().accessed.isBefore(days)) {

return dir;
}
if (currentLevel > maxLevel) {
return;
} else {
try {
for (FileSystemEntity entity
in dir.listSync(recursive: false, followLinks: false)) {
FileSystemEntityType type =
FileSystemEntity.typeSync(entity.path, followLinks: false);
if (type == typ) {
if (path.basename(entity.path) == ".virtualenvs") {

return entity;
}
if ([
"Documents",
"Applications",
"Desktop",
"Movies",
"Music",
"Pictures",
"Public"
].indexOf(path.basename(dir.path)) !=
-1) {
continue;
}
filesInDirectoryWithDepth(
entity, typ, currentLevel + 1, maxLevel);
}
}
} catch (e) {}
}
}
63 changes: 38 additions & 25 deletions lib/apps/ruby.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ import 'dart:io';
import '../utils.dart';
import '../filesize.dart';
import 'dart:convert';
import './ruby_utils.dart';
import 'dart:isolate';

final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/gems');

void runGetDirectorySize(SendPort sendPort) {
filesInDirectoryWithDepth(
Directory(userHome), FileSystemEntityType.directory, 0, 4, sendPort);
}

class RubyTask extends Task {
String app = "ruby";
Expand All @@ -12,40 +21,44 @@ class RubyTask extends Task {
@override
scan() async {
// final String workon = Platform.environment["GEM_HOME"];
var p = Process.start("/usr/bin/printenv", [r"GEM_HOME"]);
p.then((process) {
process.stdout.transform(utf8.decoder).listen((workon) {
_scan(workon.trim());
});
}).catchError((e){
this.eventBus.fire(TaskData(this.app, e.toString()));
}

);
// _scan(workon.trim());
// var p = Process.start("rvm", [r"gemdir"]);
// p.then((process) {
// process.stdout.transform(utf8.decoder).listen((workon) {
// _scan(workon.trim());
// });
// }).catchError((e){
// this.eventBus.fire(TaskData(this.app, e.toString()));
// } );
ReceivePort receivePort = ReceivePort();
var isolate = await Isolate.spawn(runGetDirectorySize, receivePort.sendPort,
onExit: receivePort.sendPort);

receivePort.listen((data) {
_scan(data);
isolate.kill(priority: 0);
});
}

_scan(String workon) async {
_scan(out) async {
final days = new DateTime.now().subtract(new Duration(days: 90));
var dirs = await filesInDirectory(
Directory(workon), FileSystemEntityType.directory);
var dirs = await filesInDirectory(out, FileSystemEntityType.directory);
int total = 0;
Stream.fromIterable(dirs)
.skipWhile((element) => element.statSync().accessed.isAfter(days))
.asyncMap(
(event) async => {"dir": event, "size": await directorySize(event)})
.listen((event) {
print(event);
this.cache.add(event["dir"]);
.asyncMap((event) async {
var size = await directorySize(event);
var data = {"dir": event, "size": size};
return data;
}).listen((event) {
this.cache.add(event);
this.eventBus.fire(TaskData(this.app, event["dir"].path.toString()));
total += event["size"];
},onError: (e){
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
this
.eventBus
.fire(TaskState(this.app, TaskStatus.done, TaskType.scan, total));
}).onDone(() {
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
if (total == 0) {
this.eventBus.fire(TaskData(this.app, "empty"));
} else {
this.eventBus.fire(TaskData(this.app, fileSizeHumanReadable(total)));
}
this
.eventBus
.fire(TaskState(this.app, TaskStatus.done, TaskType.scan, total));
Expand Down
60 changes: 60 additions & 0 deletions lib/apps/ruby_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import 'package:path/path.dart' as path;
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType;
import 'dart:isolate';

final RegExp re = new RegExp(r'\.rvm/gems/ruby\-(\d+\.\d+(?:\.\d+)?)/gems');

filesInDirectoryWithDepth(Directory dir, FileSystemEntityType typ,
int currentLevel, int maxLevel,SendPort sendPort) {

if ([
"Documents",
"Applications",
"Desktop",
"Movies",
"Music",
"Pictures",
"Public"
].indexOf(path.basename(dir.path)) !=
-1) {
return;
}

if (re.hasMatch(dir.path) ) {
sendPort.send(dir);

return;
}
if (currentLevel > maxLevel) {
return;
} else {
try {
for (FileSystemEntity entity
in dir.listSync(recursive: false, followLinks: false)) {
FileSystemEntityType type =
FileSystemEntity.typeSync(entity.path, followLinks: false);
if (type == typ) {
if (re.hasMatch(entity.path)) {
sendPort.send(entity);

return;
}
if ([
"Documents",
"Applications",
"Desktop",
"Movies",
"Music",
"Pictures",
"Public"
].indexOf(path.basename(dir.path)) !=
-1) {
return;
}
filesInDirectoryWithDepth(
entity, typ, currentLevel + 1, maxLevel,sendPort);
}
}
} catch (e) {}
}
}
11 changes: 8 additions & 3 deletions lib/utils.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType;
import 'dart:io' show Directory, File, FileSystemEntity, FileSystemEntityType,Platform;

final String userHome =
Platform.environment['HOME'] ?? Platform.environment['USERPROFILE'];

filesInDirectory(Directory dir, FileSystemEntityType typ) async {
List<dynamic> files = <dynamic>[];
if (!dir.existsSync()) {

if (dir == null || !dir.existsSync()) {
return [];
}
await for (FileSystemEntity entity
in dir.list(recursive: false, followLinks: false)) {
FileSystemEntityType type = await FileSystemEntity.type(entity.path);
if (type == typ) {
//FileSystemEntityType.file
files.add(entity);
}
}
Expand All @@ -19,6 +21,9 @@ filesInDirectory(Directory dir, FileSystemEntityType typ) async {


directorySize(Directory dir) async {
if(!dir.existsSync()){
return 0;
}
var total = 0;
await for (var entity in dir.list(recursive: true, followLinks: false)) {
FileSystemEntityType type =
Expand Down
4 changes: 2 additions & 2 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PODS:

DEPENDENCIES:
- disk_space (from `Flutter/ephemeral/.symlinks/plugins/disk_space/macos`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64`)
- FlutterMacOS (from `Flutter/ephemeral/.symlinks/flutter/darwin-x64-release`)
- path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)
- url_launcher (from `Flutter/ephemeral/.symlinks/plugins/url_launcher/macos`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)
Expand All @@ -19,7 +19,7 @@ EXTERNAL SOURCES:
disk_space:
:path: Flutter/ephemeral/.symlinks/plugins/disk_space/macos
FlutterMacOS:
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64
:path: Flutter/ephemeral/.symlinks/flutter/darwin-x64-release
path_provider_macos:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos
url_launcher:
Expand Down

0 comments on commit e1fa38f

Please sign in to comment.