Skip to content

Commit

Permalink
Remove print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
za-creature committed Jan 13, 2025
1 parent b606c5c commit 928258a
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 96 deletions.
3 changes: 2 additions & 1 deletion bindings/dart/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ analyzer:

linter:
rules:
unawaited_futures: true
- unawaited_futures
- avoid_print
57 changes: 29 additions & 28 deletions bindings/dart/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
- avoid_print
# - prefer_single_quotes


# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
28 changes: 7 additions & 21 deletions bindings/dart/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';

import 'package:async/async.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:ouisync/ouisync.dart';
import 'package:ouisync/native_channels.dart';
Expand Down Expand Up @@ -160,49 +159,36 @@ class _MyAppState extends State<MyApp> {
File? newFile;

try {
if (kDebugMode) {
print('Creating file $filePath');
}
debugPrint('Creating file $filePath');
newFile = await File.create(repo, filePath);
} catch (e) {
if (kDebugMode) {
print('Error creating file $filePath: $e');
}
debugPrint('Error creating file $filePath: $e');
}

return newFile!;
}

Future<void> saveFile(
File file, String path, Stream<List<int>> stream) async {
if (kDebugMode) {
print('Writing file $path');
}
Future<void> saveFile(File file, String path, Stream<List<int>> stream) async {
debugPrint('Writing file $path');

int offset = 0;

try {
final streamReader = ChunkedStreamReader(stream);
while (true) {
final buffer = await streamReader.readChunk(64000);
if (kDebugMode) {
print('Buffer size: ${buffer.length} - offset: $offset');
}
debugPrint('Buffer size: ${buffer.length} - offset: $offset');

if (buffer.isEmpty) {
if (kDebugMode) {
print('The buffer is empty; reading from the stream is done!');
}
debugPrint('The buffer is empty; reading from the stream is done!');
break;
}

await file.write(offset, buffer);
offset += buffer.length;
}
} catch (e) {
if (kDebugMode) {
print('Exception writing the file $path:\n${e.toString()}');
}
debugPrint('Exception writing the file $path:\n${e.toString()}');
} finally {
await file.close();
}
Expand Down
7 changes: 1 addition & 6 deletions bindings/dart/lib/bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,5 @@ DynamicLibrary _defaultLib() {
path = name;
}

if (Platform.isIOS) {
// TODO: something about this?!
return DynamicLibrary.process();
} else {
return DynamicLibrary.open(path);
}
return DynamicLibrary.open(path);
}
4 changes: 2 additions & 2 deletions bindings/dart/lib/internal/message_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:msgpack_dart/msgpack_dart.dart';
import '../exception.dart';

Uint8List encodeMessage(int id, String method, Object? args) {
//print('send: id=$id method=$method args=$args');
//debugPrint('send: id=$id method=$method args=$args');

// Message format:
//
Expand All @@ -29,7 +29,7 @@ DecodeResult decodeMessage(Uint8List bytes) {
final id = bytes.buffer.asByteData().getUint64(0, Endian.big);
final payload = deserialize(bytes.sublist(8));

//print('recv: id=$id, payload=$payload');
//debugPrint('recv: id=$id, payload=$payload');

if (payload is! Map) {
return MalformedPayload._(id);
Expand Down
7 changes: 4 additions & 3 deletions bindings/dart/lib/native_channels.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:collection';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'ouisync.dart' show Repository, File;
Expand Down Expand Up @@ -82,12 +83,12 @@ class NativeChannels {

Future<int?> _openFile(String path) async {
final id = _files.insert(await File.open(_repository!, path));
print('openFile(path=$path) -> id=$id');
debugPrint('openFile(path=$path) -> id=$id');
return id;
}

Future<void> _closeFile(int id) async {
print('closeFile(id=$id)');
debugPrint('closeFile(id=$id)');

final file = _files.remove(id);

Expand All @@ -97,7 +98,7 @@ class NativeChannels {
}

Future<Uint8List> _readFile(int id, int chunkSize, int offset) async {
print('readFile(id=$id, chunkSize=$chunkSize, offset=$offset)');
debugPrint('readFile(id=$id, chunkSize=$chunkSize, offset=$offset)');

final file = _files[id];

Expand Down
15 changes: 7 additions & 8 deletions bindings/dart/lib/ouisync.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'dart:async';
import 'dart:collection';
import 'dart:convert';
import 'dart:developer' show log;
import 'dart:typed_data';
import 'dart:math' show Random;

import 'package:flutter/foundation.dart';
import 'package:hex/hex.dart';
import 'package:ouisync/exception.dart';

Expand Down Expand Up @@ -60,7 +59,7 @@ class Session {
debugLabel: debugLabel,
);
} on ServiceAlreadyRunning catch (_) {
log('Service already started');
debugPrint('Service already started');
}
}

Expand Down Expand Up @@ -731,7 +730,7 @@ class File {
/// Throws if [path] already exists of if the parent of [path] doesn't exists.
static Future<File> create(Repository repo, String path) async {
if (debugTrace) {
print("File.create $path");
debugPrint("File.create $path");
}

return File._(
Expand Down Expand Up @@ -788,7 +787,7 @@ class File {
/// ```
Future<List<int>> read(int offset, int size) {
if (debugTrace) {
print("File.read");
debugPrint("File.read");
}

return _client.invoke<Uint8List>(
Expand All @@ -798,7 +797,7 @@ class File {
/// Write [data] to this file starting at [offset].
Future<void> write(int offset, List<int> data) {
if (debugTrace) {
print("File.write");
debugPrint("File.write");
}

return _client.invoke<void>('file_write', {
Expand All @@ -811,7 +810,7 @@ class File {
/// Truncate the file to [size] bytes.
Future<void> truncate(int size) {
if (debugTrace) {
print("File.truncate");
debugPrint("File.truncate");
}

return _client.invoke<void>('file_truncate', {
Expand All @@ -823,7 +822,7 @@ class File {
/// Returns the length of this file in bytes.
Future<int> get length {
if (debugTrace) {
print("File.length");
debugPrint("File.length");
}

return _client.invoke<int>('file_len', _handle);
Expand Down
14 changes: 7 additions & 7 deletions bindings/dart/lib/state_monitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ class StateMonitor {
@override
String toString() => "StateMonitor($_path)";

Future<StateMonitorNode?> load() async {
Future<StateMonitorNode> load() async {
try {
final list = await _client.invoke(
"state_monitor_get", _path.map((id) => id.toString()))
as List<Object?>;
final List<Object?> list = await _client.invoke(
"state_monitor_get", _path.map((id) => id.toString())
);
return StateMonitorNode._decode(_path, list);
} catch (e) {
print('failed to load state monitor node at $_path: $e');
return null;
} catch (e, st) {
final wrapped = Exception('failed to load state monitor node at $_path: ${e.toString()}');
Error.throwWithStackTrace(wrapped, st);
}
}
}
17 changes: 9 additions & 8 deletions bindings/dart/test/add_file_folder_syncing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;

import 'package:flutter/foundation.dart';
import 'package:ouisync/ouisync.dart';
import 'package:test/test.dart';

Expand All @@ -20,7 +21,7 @@ void main() {

Future<void> getDirectoryContents(Repository repo, String path) async {
final folder1Contents = await Directory.read(repo, path);
print('Directory contents: ${folder1Contents.toList()}');
debugPrint('Directory contents: ${folder1Contents.toList()}');
}

setUp(() async {
Expand All @@ -43,7 +44,7 @@ void main() {
currentPath = '/';

subscription = repository.events.listen((_) async {
print('Syncing $currentPath');
debugPrint('Syncing $currentPath');
await getDirectoryContents(repository, currentPath);
});
});
Expand All @@ -58,11 +59,11 @@ void main() {
// Create folder1 (/folder1)
{
await Directory.create(repository, folder1Path);
print('New folder: $folder1Path');
debugPrint('New folder: $folder1Path');
}
// Create file1.txt inside folder1 (/folder1/file1.txt)
{
print('About to create file $file1InFolder1Path');
debugPrint('About to create file $file1InFolder1Path');
final file = await File.create(repository, file1InFolder1Path);
await file.write(0, utf8.encode(file1Content));
await file.close();
Expand All @@ -72,21 +73,21 @@ void main() {
final folder1Contents = await Directory.read(repository, folder1Path);
expect(folder1Contents.toList().length, equals(1));

print('Folder1 contents: ${folder1Contents.toList()}');
debugPrint('Folder1 contents: ${folder1Contents.toList()}');
}
});

test('Add file with syncing in directory', () async {
// Create folder1 (/folder1)
{
await Directory.create(repository, folder1Path);
print('New folder: $folder1Path');
debugPrint('New folder: $folder1Path');

currentPath = folder1Path;
}
// Create file1 inside folder1 (/folder1/file1.txt)
{
print('About to create new file $file1InFolder1Path');
debugPrint('About to create new file $file1InFolder1Path');
final file = await File.create(repository, file1InFolder1Path);
await file.write(0, utf8.encode(file1Content));
await file.close();
Expand All @@ -96,7 +97,7 @@ void main() {
final folder1Contents = await Directory.read(repository, folder1Path);
expect(folder1Contents.toList().length, equals(1));

print('Folder1 contents: ${folder1Contents.toList()}');
debugPrint('Folder1 contents: ${folder1Contents.toList()}');
}
});
}
Loading

0 comments on commit 928258a

Please sign in to comment.