-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdm_status.rb
136 lines (103 loc) · 3.45 KB
/
dm_status.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# encoding: UTF-8
require 'yaml'
class DM_Status
attr_accessor :status_name, :status_path,
#Process modes. UI sets to true to trigger a process.
# Process sets to false when done.
:enabled,
:download,
:convert,
:consolidate,
:job_uuid,
#Files downloaded stats --> Progress bar.
:files_total,
:files_local,
:file_size_mb,
:files_consolidated,
#File conversion stats --> Progress bar.
:activities_total,
:activities_converted,
:file_current,
:status,
:error
def initialize
@status_name = "status.yaml"
@status_path = "./"
@job_uuid = ""
@status = ""
@files_local = 0
@error = ""
end
def status_file
return @status_path + @status_name
end
#read file.
def save_status
status_hash = {}
status_hash["job_uuid"] = @job_uuid
#Download stats.
status_hash["files_total"] = @files_total
status_hash["files_local"] = @files_local
status_hash["files_size_mb"] = @file_size_mb
#Conversion stats.
status_hash["activities_total"] = @activities_total
status_hash["activities_converted"] = @activities_converted
#Consolidation stats
status_hash["files_consolidated"] = @files_consolidated
#General details.
status_hash["file_current"] = @file_current
status_hash["status"] = @status
status_hash["error"] = @error
#Process modes.
status_hash["enabled"] = @enabled
status_hash["download"] = @download
status_hash["convert"] = @convert
status_hash["consolidate"] = @consolidate
File.open(status_file, 'w') do |f| #This should NEVER append.
f.write status_hash.to_yaml
end
end
#Open YAML file and load settings into config object.
def get_status
#Create status file if needed...
begin
status_hash = YAML::load_file(status_file)
rescue
save_status
status_hash = YAML::load_file(status_file)
end
@job_uuid = status_hash["job_uuid"]
@files_total = status_hash["files_total"]
@files_local = status_hash["files_local"]
@file_size_mb = status_hash["files_size_mb"]
#Conversion stats.
@activities_total = status_hash["activities_total"]
@activities_converted = status_hash["activities_converted"]
#Consolidation stats.
@files_consolidated = status_hash["files_consolidated"]
@file_current = status_hash["file_current"]
@status = status_hash["status"]
@error = status_hash["error"]
#Process modes.
@enabled = status_hash["enabled"]
@download = status_hash["download"]
@convert = status_hash["convert"]
@consolidate = status_hash["consolidate"]
end
end
#-------------------------------------------------
# Application UI code:
if __FILE__ == $0 #This script code is executed when running this file.
oStatus = DM_Status.new
oStatus.files_total=2000
oStatus.files_local=0
#Exercise some methods.
oStatus.save_status
oStatus.get_status
oStatus.files_total=100000
oStatus.files_local=-99999999999
oStatus.save_status
oStatus.status = "this status"
p oStatus.status
p "Have completed #{oStatus.files_local} out of #{oStatus.files_total} items..."
end