fewald-worklog 0.2.29 → 0.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/cli.rb +9 -0
  4. data/lib/takeout.rb +50 -0
  5. data/lib/worklog.rb +18 -1
  6. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73596a6293ca475df501643da1cbf039a255c2b952f80a5e85a95565e8cc9480
4
- data.tar.gz: 0513b170d3e5536738d09d832f927c9e415515ff66c0542b54f99df44766d07c
3
+ metadata.gz: 1448a0024e80bc4c30592f79384dad240264fe601595f760e6cfd9d239bc3fcf
4
+ data.tar.gz: 8ac2ece9829a3bce2d6713a2c99fed746142511af900f7ad4129d62289982496
5
5
  SHA512:
6
- metadata.gz: c4d4dfca71d25dfb9cf69168d5db09df888910d51ae7c0853b060b00ef2014e79b67384d63f3195b8ecf25287801476a5d11ef46f045bcf267d678096d4c770f
7
- data.tar.gz: b40d954290deaf1a2aa741e9665dc45f0bf0dcc7fefb72f88e9d72a4c3f745e4ddd790aca1e5c34a4dd8b0e5801c80282bbd9660e0a52c417dd52f336434867b
6
+ metadata.gz: 0a0c67bfa31766e1e56c5f7a45c9efff5dabbf177f03d1a358054079966228d68b3d0ba37bb19acca8d1d7540f2b89709b1fc03f21d3dac29266bd15b8238f2f
7
+ data.tar.gz: f664b7b885a37b5c4659e0484b37fb85c3ebba5e81b4ef565d0522e3f8ff925816cd220baba0b3a3b617ceec1db5c65d181fd8597e92d0d9b0d782188cc6dc77
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.29
1
+ 0.2.31
data/lib/cli.rb CHANGED
@@ -136,6 +136,15 @@ class WorklogCLI < Thor
136
136
  worklog.tags(tag, options)
137
137
  end
138
138
 
139
+ desc 'takeout', <<~EOF
140
+ Export all work log data as a tar.gz archive. The archive contains all log files and settings.
141
+ The filename will be in the format worklog_takeout_YYYYMMDD_HHMMSS.tar.gz
142
+ EOF
143
+ def takeout
144
+ worklog = Worklog::Worklog.new
145
+ worklog.takeout
146
+ end
147
+
139
148
  desc 'server', 'Start the work log server'
140
149
  def server
141
150
  worklog = Worklog::Worklog.new
data/lib/takeout.rb ADDED
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'zlib'
4
+ require 'rubygems/package'
5
+ require 'stringio'
6
+
7
+ module Worklog
8
+ # Exporter for worklog entries to a compressed tarball.
9
+ class Takeout
10
+ # Constructor
11
+ # @param configuration [Configuration] The application configuration
12
+ def initialize(configuration)
13
+ @configuration = configuration
14
+ end
15
+
16
+ # Retrieves all files from the storage path.
17
+ # @return [Array<String>] List of file paths
18
+ def all_files
19
+ Dir.glob(File.join(@configuration.storage_path, '*')).select { |file| File.file?(file) }
20
+ end
21
+
22
+ # Creates a tar.gz archive of all worklog files, including settings.
23
+ # @return [String] The tar.gz data as a binary string
24
+ def to_tar_gz
25
+ tar_io = StringIO.new
26
+
27
+ Gem::Package::TarWriter.new(tar_io) do |tar|
28
+ all_files.each do |file_path|
29
+ file_name = File.basename(file_path)
30
+ File.open(file_path, 'rb') do |file|
31
+ stat = file.stat
32
+ tar.add_file(file_name, stat.mode, stat.mtime) do |tar_file|
33
+ IO.copy_stream(file, tar_file)
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ # Compress the tar data with gzip
40
+ gz_io = StringIO.new
41
+ Zlib::GzipWriter.wrap(gz_io) do |gzip|
42
+ tar_io.rewind
43
+ IO.copy_stream(tar_io, gzip)
44
+ end
45
+ gz_io.rewind
46
+
47
+ gz_io.string
48
+ end
49
+ end
50
+ end
data/lib/worklog.rb CHANGED
@@ -14,9 +14,10 @@ require 'storage'
14
14
  require 'worklogger'
15
15
  require 'string_helper'
16
16
  require 'printer'
17
+ require 'project_storage'
17
18
  require 'statistics'
18
19
  require 'summary'
19
- require 'project_storage'
20
+ require 'takeout'
20
21
 
21
22
  module Worklog
22
23
  # Main class providing all worklog functionality.
@@ -284,6 +285,22 @@ module Worklog
284
285
  end
285
286
  end
286
287
 
288
+ # Export all work log data as a tar.gz archive.
289
+ # The archive contains all log files and settings.
290
+ # The filename will be in the format worklog_takeout_YYYYMMDD_HHMMSS.tar.gz
291
+ def takeout
292
+ takeout = Takeout.new(@config)
293
+ tar_gz_data = takeout.to_tar_gz
294
+
295
+ filename = "worklog_takeout_#{Time.now.strftime('%Y%m%d_%H%M%S')}.tar.gz"
296
+ File.binwrite(filename, tar_gz_data)
297
+
298
+ WorkLogger.info Rainbow("Created takeout archive: #{filename}").green
299
+
300
+ # Return filename for further processing if needed
301
+ filename
302
+ end
303
+
287
304
  # Show overview of all tags used in the work log including their count.
288
305
  def tag_overview
289
306
  all_logs = @storage.all_days
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.29
4
+ version: 0.2.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald
@@ -137,6 +137,7 @@ files:
137
137
  - lib/storage.rb
138
138
  - lib/string_helper.rb
139
139
  - lib/summary.rb
140
+ - lib/takeout.rb
140
141
  - lib/templates/favicon.svg.erb
141
142
  - lib/templates/index.html.erb
142
143
  - lib/version.rb