-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubz_commands_sections.py
162 lines (123 loc) · 5.54 KB
/
subz_commands_sections.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import sublime
import sublime_plugin
import datetime
try:
from .subz_tools_subl import *
from .subz_sections import *
except ValueError:
from subz_tools_subl import *
from subz_sections import *
class SubzInsertSectionAvlBucketStateCommand(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, AVL_BUCKET_STATE)
class SubzInsertSectionAvlInv(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, AVL_INV)
class SubzInsertSectionAvlState(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, AVL_STATE)
class SubzInsertSectionContractFull(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, CONTRACT_FULL)
class SubzInsertSectionContractMinimal(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, CONTRACT_MINIMAL)
class SubzInsertSectionContractSpo(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, CONTRACT_SPO)
class SubzInsertSectionDefHotel(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, DEF_HOTEL)
class SubzInsertSectionDefMeal(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, DEF_MEAL)
class SubzInsertSectionDefRoom(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, DEF_ROOM)
class SubzInsertSectionQueryTransform(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, QUERY_TRANSFORM)
class SubzInsertSectionRateBase(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_BASE)
class SubzInsertSectionRateCnx(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_CNX)
class SubzInsertSectionRateDiscount(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_DISCOUNT)
class SubzInsertSectionRateDiscountGroup(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_DISCOUNT_GROUP)
class SubzInsertSectionRatePlan(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_PLAN)
class SubzInsertSectionRateRule(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_RULE)
class SubzInsertSectionRateSupplement(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_SUPPLEMENT)
class SubzInsertSectionTax(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, TAX)
class SubzInsertSectionTaxGroup(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, TAX_GROUP)
class SubzInsertSectionRestriction(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RESTRICTION)
class SubzInsertSectionTest(sublime_plugin.TextCommand):
def run(self, edit):
today = datetime.date.today()
checkin = datetime.datetime(year=today.year + 1, month=1, day=1)
today_formatted = today.strftime("%Y%m%d")
checkin_formatted = checkin.strftime("%Y%m%d")
hotel_code = get_contract_section_string_type_value(self.view, "hotel_code", "TEST")
source = get_contract_section_string_type_value(self.view, "source", "TEST")
sample_query = "HB{0}${1}:{2}/{3}+1/A1".format(today_formatted, source, hotel_code, checkin_formatted)
test = TEST.replace("SAMPLE_QUERY", sample_query)
insert_ariz_section(self, edit, test)
class SubzInsertSectionRateSupplementCat(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_SUPPLEMENT_CAT)
class SubzInsertSectionRateDiscountCat(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, RATE_DISCOUNT_CAT)
class SubzInsertSectionConfig(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, CONFIG)
class SubzInsertSectionCustomInfo(sublime_plugin.TextCommand):
def run(self, edit):
insert_ariz_section(self, edit, CUSTOM_INFO)
class SubzReformatAriz(sublime_plugin.TextCommand):
def run(self, edit):
SubzAddAllSectionsHeaders.run(self, edit)
SubzFormatAllSections.run(self, edit)
class SubzAddAllSectionsHeaders(sublime_plugin.TextCommand):
def run(self, edit):
for section in SECTIONS_WITH_COLUMN_HEADERS:
section_lines = split_section_to_lines(section)
header_regex = section_header_regex(section_lines)
basic_header = section_basic_header(section_lines)
find_and_replace(self, edit, header_regex, basic_header)
class SubzFormatAllSections(sublime_plugin.TextCommand):
def run(self, edit):
result = is_package_installed("Table Editor")
if result == False:
sublime.message_dialog("To format sections you need to install Package 'Table Editor'\nhttps://packagecontrol.io/packages/Table%20Editor")
else:
self.view.sel().clear()
header_regions = self.view.find_all(r"^\|(?!.*\n\|)", 0)
number_of_regions = len(header_regions)
if number_of_regions == 0:
sublime.message_dialog("No sections have been found")
else:
for region in header_regions:
self.view.sel().add(region)
sublime.active_window().run_command('table_editor_next_field')
self.view.sel().clear()
# table editor next_field adds new row in single-column tables, we need to remove them
empty_rows_regions = self.view.find_all(r"^[\s\n|]*$")
for region in reversed(empty_rows_regions):
self.view.replace(edit, region, "")