-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgitter_done.py
205 lines (167 loc) · 6.76 KB
/
gitter_done.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""
Git<->P4 command line automation interface script.
Automates the processes that allows us to follow lightweight branching
strategies between Git & P4 source control solutions.
Attributes:
LOGGER_OUTPUT_DIR_NAME (str): Name of the output directory to log to.
TITLE_PROMPT (str): Some ASCII Art to make things pretty.
IGNORED_FILE_LIST (list): A list of file paths that should be ignored by
the main source control when building the change lists
if they show modifications.
GIT_FILE_WISHLIST (list): A list of file paths containing the files and
folders we actually want to track in git.
GIT_FILE_IGNORE_LIST (list): A list of file paths containing the files and
and folders we want to absolutely ignore in git.
"""
import logging
import os
import sys
import bin.GitterDone.config as config
import bin.GitterDone.git_utility as git
import bin.GitterDone.string_utility as str_utility
import bin.GitterDone.console_utility as console_utility
import bin.GitterDone.arg_parser_utility as arg_parser_utility
import bin.GitterDone.logging_utility as logging_utility
import bin.GitterDone.python_utility as python_utility
import bin.GitterDone.p4_utility as p4_utility
# ============================================================================
# Global Variables.
LOGGER_OUTPUT_DIR_NAME = 'GitterDoneLogs'
TITLE_PROMPT = "\
\n======================================================\
\n _____ _ _ _ _____ \
\n / ____(_) | | | | __ \\ \
\n | | __ _| |_| |_ ___ _ __| | | | ___ _ __ ___ \
\n | | |_ | | __| __/ _ \\ '__| | | |/ _ \\| '_ \\ / _ \\\
\n | |__| | | |_| || __/ | | |__| | (_) | | | | __/\
\n \\_____|_|\\__|\\__\\___|_| |_____/ \\___/|_| |_|\\___|\
\n\
\n======================================================\
\n "
# ----------------------------------
# Definitions from config.py.
IGNORED_FILE_LIST = config.get_p4_ignore_wishlist()
GIT_FILE_WISHLIST = config.get_git_ignore_desired_path_wishlist()
GIT_FILE_IGNORE_LIST = config.get_git_ignore_ignored_path_wishlist()
# ============================================================================
# =========== SETUP & TEARDOWN
def _execute_user_process(args):
"""
Execute the desired user process based on received arguments.
Args:
args(args): Argument object containing the system command line
inputs obtained from the call to execute.
Returns:
None.
"""
logging.debug(str_utility.friendly_list_to_str(sys.argv[1:]))
# First handle if at least one operation is available.
if (args.changelist is None and args.git is None
and args.update_trunk is None):
logging.error('No actionable arguments received.')
python_utility.terminate(True)
return
if args.git:
logging.info('Requested .gitignore update')
git.generate_git_ignore(GIT_FILE_WISHLIST, GIT_FILE_IGNORE_LIST)
if args.changelist is not None:
logging.info('Performing a Perforce Operation.')
p4_utility.execute_p4_offline_sync(
args.changelist, args.include_trunk, args.ignored_branches)
elif args.update_trunk is not None:
p4_utility.execute_git_sync_with_p4(args.update_trunk, args.force,
args.force_all)
# ============================================================================
# CUSTOM ARGUMENT PARSING FOR GitterDone.py
def _print_help():
"""
Print the help information to the screen.
Returns:
string: The contents of the help message.
"""
# TODO: Update Help Message.
help_message = ""
return help_message
def _add_parser_options(parser):
if parser is None:
python_utility.terminate_with_message(
'Parser set up incorrectly. GitterDone interface non-functional.')
# Trigger extracting all the local changes from a branch into a changelist.
arg_parser_utility.add_parser_option(
parser,
'-cl',
'--changelist',
help=('Generate a new changelist with all files '
'operations in a given Branch.'),
type=str,
nargs='?',
action='store',
const='',
metavar='Branch')
# Option to include master branch changes when generating p4 CL.
arg_parser_utility.add_parser_option(
parser,
full_name='--include_trunk',
help=('Flag to wheter include the trunk branch file '
'operations on the changelist.'),
action='store_true',
default=None)
# Trigger automatically generating a new .gitignore.
arg_parser_utility.add_parser_option(
parser,
'-g',
'--git',
help='Regenerate the .gitignore file to be used by the repository.',
action='store_true',
default=None)
# Update the master branch to either existing CL or new CL from P4.
arg_parser_utility.add_parser_option(
parser,
'-u',
'--update_trunk',
help=('Updates the trunk branch to the latest available CL in'
'SourceDepot. If a CL is given, updates to that CL instead.'),
type=str,
nargs='?',
action='store',
const='',
metavar=('CL'))
# Forces the P4 update operation so that files are clobbered.
arg_parser_utility.add_parser_option(
parser,
'-f',
'--force',
help='Flag to force update operations.',
action='store_true',
default=None)
# Forces each file in the tree to be clobbered.
arg_parser_utility.add_parser_option(
parser,
'-fa',
'--force_all',
action='store_true',
help=('Enable this flag to force sync all the '
'tracked files. (POTENTIALLY SLOW)'),
default=None)
# Ignore certain branches when generating the CL for P4.
arg_parser_utility.add_parser_option(
parser, '-ig', '--ignored_branches', nargs='+', default=None)
# ============================================================================
# MAIN
if __name__ == '__main__':
# Only run this if we are the main script being run.
console_utility.console_prompt(TITLE_PROMPT)
PARSER = arg_parser_utility.setup_parser(help_message=_print_help())
_add_parser_options(PARSER)
ARGS = PARSER.parse_args()
logging_utility.set_log_level(
desired_log_level=ARGS.loglevel,
log_to_file=True,
log_output_path=(
logging_utility.get_logger_output_path(LOGGER_OUTPUT_DIR_NAME,
False)),
log_output_filename=os.path.basename(__file__))
python_utility.verify_python_version()
_execute_user_process(ARGS)
# Exit if we are done.
python_utility.terminate(False)