-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine_and_archive.rb
62 lines (51 loc) · 2.43 KB
/
combine_and_archive.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
require 'date'
require 'fileutils'
require_relative './lib/library'
require_relative './lib/environment'
def import_sap_files
# import sap files
move_files(CSV_SFTP_FILES, CSV_ACTUALS, read_directory(CSV_SFTP_FILES))
end
def combine_and_archive
# Get today combined opex and capex filenames from the current folder
files = read_directory(CSV_ACTUALS)
opex_files = get_opex_files_by_extension(files, ".gz")
capex_files = get_capex_files_by_extension(files, ".gz")
capex_depr_files = get_capex_depr_files_by_extension(files, ".gz")
# combined file names
combined_opex_name = "combined_opex.csv"
combined_capex_name = "combined_capex.csv"
combined_capex_depr_name = "combined_capex_depr.csv"
# list opex_files
puts "\ncount opex files: #{opex_files.length}"
opex_files.each { |file| puts file }
# list capex_files
puts "\ncount capex files: #{capex_files.length}"
capex_files.each { |file| puts file }
# list capex_depr_files
puts "\ncount capex_depr files: #{capex_depr_files.length}"
capex_depr_files.each { |file| puts file }
# # delete previous combined files
remove_specific_files(CSV_ACTUALS, combined_capex_name)
remove_specific_files(CSV_ACTUALS, combined_opex_name)
remove_specific_files(CSV_ACTUALS, combined_capex_depr_name)
# # combine files
merge_file(combined_opex_name, "opex", opex_files, CSV_ACTUALS, CSV_ACTUALS)
merge_file(combined_capex_name, "capex", capex_files, CSV_ACTUALS, CSV_ACTUALS)
merge_file(combined_capex_depr_name, "capex_depr", capex_depr_files, CSV_ACTUALS, CSV_ACTUALS)
# get full datetime
full_datetime = get_full_datetime
# create a directory with full_datetime
create_directory(CSV_ARCHIVE+full_datetime) if (opex_files.length + capex_files.length + capex_depr_files.length) > 0
# move opex and capex .gz files to archive folder
move_files(CSV_ACTUALS, (CSV_ARCHIVE+full_datetime), opex_files)
move_files(CSV_ACTUALS, (CSV_ARCHIVE+full_datetime), capex_files)
move_files(CSV_ACTUALS, (CSV_ARCHIVE+full_datetime), capex_depr_files)
# As the interface is failing when a file is not found and the next file is not imported even if exists,
# we are now adding empty files in case they didn't exists.
create_empty_csv(CSV_ACTUALS, combined_opex_name, "opex")
create_empty_csv(CSV_ACTUALS, combined_capex_name, "capex")
end
clean_sap_files
import_sap_files
combine_and_archive