Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
configuration
Commits
82d68623
Commit
82d68623
authored
Aug 04, 2017
by
Shirley He
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add error handling for max 3 fields
parent
421da388
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
util/generate_permutations.py
+11
-9
No files found.
util/generate_permutations.py
View file @
82d68623
...
...
@@ -11,27 +11,30 @@ import sys
def
parse_field_arguments
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--fields'
,
nargs
=
3
,
action
=
"append"
,
default
=
None
,
parser
.
add_argument
(
'--fields'
,
nargs
=
"*"
,
action
=
"append"
,
default
=
None
,
help
=
"Specify which fields to generate permutations on"
)
parser
.
add_argument
(
'filename'
)
args
=
parser
.
parse_args
()
file
=
open
(
args
.
filename
)
num_args
=
parser
.
parse_args
()
if
(
len
(
num_args
.
fields
[
0
])
>
3
):
raise
argparse
.
ArgumentTypeError
(
"--fields can only take a max of 3 values"
)
file
=
open
(
num_args
.
filename
)
permutation_data
=
json
.
load
(
file
)
first_field
=
permutation_data
second_field
=
permutation_data
third_field
=
permutation_data
# if no field arguments are given, just print out default data
if
not
args
.
fields
:
if
not
num_
args
.
fields
:
default_permutation
=
permutation_data
[
"default_data"
]
print
default_permutation
else
:
for
permutation_choices
in
args
.
fields
:
for
permutation_choices
in
num_
args
.
fields
:
first_field
=
first_field
[
"permutation_data"
][
permutation_choices
[
0
]]
second_field
=
second_field
[
"permutation_data"
][
permutation_choices
[
1
]]
third_field
=
third_field
[
"permutation_data"
][
permutation_choices
[
2
]]
return
first_field
,
second_field
,
third_field
...
...
@@ -39,9 +42,8 @@ def parse_field_arguments():
def
generate_permutations
(
fields
):
#permutation_generation = [first_field, second_field, third_field]
print
list
(
product
(
*
fields
))
# print fields
# print list(product(*fields))
print
""
if
__name__
==
"__main__"
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment