repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
uwdata/draco
draco/run.py
run_clingo
def run_clingo( draco_query: List[str], constants: Dict[str, str] = None, files: List[str] = None, relax_hard=False, silence_warnings=False, debug=False, ) -> Tuple[str, str]: """ Run draco and return stderr and stdout """ # default args files = files or DRACO_LP if rela...
python
def run_clingo( draco_query: List[str], constants: Dict[str, str] = None, files: List[str] = None, relax_hard=False, silence_warnings=False, debug=False, ) -> Tuple[str, str]: """ Run draco and return stderr and stdout """ # default args files = files or DRACO_LP if rela...
[ "def", "run_clingo", "(", "draco_query", ":", "List", "[", "str", "]", ",", "constants", ":", "Dict", "[", "str", ",", "str", "]", "=", "None", ",", "files", ":", "List", "[", "str", "]", "=", "None", ",", "relax_hard", "=", "False", ",", "silence_...
Run draco and return stderr and stdout
[ "Run", "draco", "and", "return", "stderr", "and", "stdout" ]
b130b5ebdb369e18e046706c73dc9c29b8159f7f
https://github.com/uwdata/draco/blob/b130b5ebdb369e18e046706c73dc9c29b8159f7f/draco/run.py#L74-L118
train
uwdata/draco
draco/run.py
run
def run( draco_query: List[str], constants: Dict[str, str] = None, files: List[str] = None, relax_hard=False, silence_warnings=False, debug=False, clear_cache=False, ) -> Optional[Result]: """ Run clingo to compute a completion of a partial spec or violations. """ # Clear file cache...
python
def run( draco_query: List[str], constants: Dict[str, str] = None, files: List[str] = None, relax_hard=False, silence_warnings=False, debug=False, clear_cache=False, ) -> Optional[Result]: """ Run clingo to compute a completion of a partial spec or violations. """ # Clear file cache...
[ "def", "run", "(", "draco_query", ":", "List", "[", "str", "]", ",", "constants", ":", "Dict", "[", "str", ",", "str", "]", "=", "None", ",", "files", ":", "List", "[", "str", "]", "=", "None", ",", "relax_hard", "=", "False", ",", "silence_warning...
Run clingo to compute a completion of a partial spec or violations.
[ "Run", "clingo", "to", "compute", "a", "completion", "of", "a", "partial", "spec", "or", "violations", "." ]
b130b5ebdb369e18e046706c73dc9c29b8159f7f
https://github.com/uwdata/draco/blob/b130b5ebdb369e18e046706c73dc9c29b8159f7f/draco/run.py#L121-L178
train
thiderman/doge
doge/wow.py
DogeDeque.get
def get(self): """ Get one item. This will rotate the deque one step. Repeated gets will return different items. """ self.index += 1 # If we've gone through the entire deque once, shuffle it again to # simulate ever-flowing random. self.shuffle() will run __ini...
python
def get(self): """ Get one item. This will rotate the deque one step. Repeated gets will return different items. """ self.index += 1 # If we've gone through the entire deque once, shuffle it again to # simulate ever-flowing random. self.shuffle() will run __ini...
[ "def", "get", "(", "self", ")", ":", "self", ".", "index", "+=", "1", "if", "self", ".", "index", "==", "len", "(", "self", ")", ":", "self", ".", "shuffle", "(", ")", "self", ".", "rotate", "(", "1", ")", "try", ":", "return", "self", "[", "...
Get one item. This will rotate the deque one step. Repeated gets will return different items.
[ "Get", "one", "item", ".", "This", "will", "rotate", "the", "deque", "one", "step", ".", "Repeated", "gets", "will", "return", "different", "items", "." ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/wow.py#L29-L48
train
thiderman/doge
doge/wow.py
DogeDeque.shuffle
def shuffle(self): """ Shuffle the deque Deques themselves do not support this, so this will make all items into a list, shuffle that list, clear the deque, and then re-init the deque. """ args = list(self) random.shuffle(args) self.clear() sup...
python
def shuffle(self): """ Shuffle the deque Deques themselves do not support this, so this will make all items into a list, shuffle that list, clear the deque, and then re-init the deque. """ args = list(self) random.shuffle(args) self.clear() sup...
[ "def", "shuffle", "(", "self", ")", ":", "args", "=", "list", "(", "self", ")", "random", ".", "shuffle", "(", "args", ")", "self", ".", "clear", "(", ")", "super", "(", "DogeDeque", ",", "self", ")", ".", "__init__", "(", "args", ")" ]
Shuffle the deque Deques themselves do not support this, so this will make all items into a list, shuffle that list, clear the deque, and then re-init the deque.
[ "Shuffle", "the", "deque" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/wow.py#L55-L68
train
thiderman/doge
doge/wow.py
FrequencyBasedDogeDeque.get
def get(self): """ Get one item and prepare to get an item with lower rank on the next call. """ if len(self) < 1: return "wow" if self.index >= len(self): self.index = 0 step = random.randint(1, min(self.step, len(self))) res =...
python
def get(self): """ Get one item and prepare to get an item with lower rank on the next call. """ if len(self) < 1: return "wow" if self.index >= len(self): self.index = 0 step = random.randint(1, min(self.step, len(self))) res =...
[ "def", "get", "(", "self", ")", ":", "if", "len", "(", "self", ")", "<", "1", ":", "return", "\"wow\"", "if", "self", ".", "index", ">=", "len", "(", "self", ")", ":", "self", ".", "index", "=", "0", "step", "=", "random", ".", "randint", "(", ...
Get one item and prepare to get an item with lower rank on the next call.
[ "Get", "one", "item", "and", "prepare", "to", "get", "an", "item", "with", "lower", "rank", "on", "the", "next", "call", "." ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/wow.py#L86-L103
train
thiderman/doge
doge/core.py
onscreen_len
def onscreen_len(s): """ Calculate the length of a unicode string on screen, accounting for double-width characters """ if sys.version_info < (3, 0) and isinstance(s, str): return len(s) length = 0 for ch in s: length += 2 if unicodedata.east_asian_width(ch) == 'W' else 1 ...
python
def onscreen_len(s): """ Calculate the length of a unicode string on screen, accounting for double-width characters """ if sys.version_info < (3, 0) and isinstance(s, str): return len(s) length = 0 for ch in s: length += 2 if unicodedata.east_asian_width(ch) == 'W' else 1 ...
[ "def", "onscreen_len", "(", "s", ")", ":", "if", "sys", ".", "version_info", "<", "(", "3", ",", "0", ")", "and", "isinstance", "(", "s", ",", "str", ")", ":", "return", "len", "(", "s", ")", "length", "=", "0", "for", "ch", "in", "s", ":", "...
Calculate the length of a unicode string on screen, accounting for double-width characters
[ "Calculate", "the", "length", "of", "a", "unicode", "string", "on", "screen", "accounting", "for", "double", "-", "width", "characters" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L400-L414
train
thiderman/doge
doge/core.py
Doge.setup_seasonal
def setup_seasonal(self): """ Check if there's some seasonal holiday going on, setup appropriate Shibe picture and load holiday words. Note: if there are two or more holidays defined for a certain date, the first one takes precedence. """ # If we've specified a...
python
def setup_seasonal(self): """ Check if there's some seasonal holiday going on, setup appropriate Shibe picture and load holiday words. Note: if there are two or more holidays defined for a certain date, the first one takes precedence. """ # If we've specified a...
[ "def", "setup_seasonal", "(", "self", ")", ":", "if", "self", ".", "ns", ".", "season", ":", "return", "self", ".", "load_season", "(", "self", ".", "ns", ".", "season", ")", "if", "self", ".", "ns", ".", "doge_path", "is", "not", "None", "and", "n...
Check if there's some seasonal holiday going on, setup appropriate Shibe picture and load holiday words. Note: if there are two or more holidays defined for a certain date, the first one takes precedence.
[ "Check", "if", "there", "s", "some", "seasonal", "holiday", "going", "on", "setup", "appropriate", "Shibe", "picture", "and", "load", "holiday", "words", "." ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L75-L106
train
thiderman/doge
doge/core.py
Doge.apply_text
def apply_text(self): """ Apply text around doge """ # Calculate a random sampling of lines that are to have text applied # onto them. Return value is a sorted list of line index integers. linelen = len(self.lines) affected = sorted(random.sample(range(linelen),...
python
def apply_text(self): """ Apply text around doge """ # Calculate a random sampling of lines that are to have text applied # onto them. Return value is a sorted list of line index integers. linelen = len(self.lines) affected = sorted(random.sample(range(linelen),...
[ "def", "apply_text", "(", "self", ")", ":", "linelen", "=", "len", "(", "self", ".", "lines", ")", "affected", "=", "sorted", "(", "random", ".", "sample", "(", "range", "(", "linelen", ")", ",", "int", "(", "linelen", "/", "3.5", ")", ")", ")", ...
Apply text around doge
[ "Apply", "text", "around", "doge" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L116-L138
train
thiderman/doge
doge/core.py
Doge.load_doge
def load_doge(self): """ Return pretty ASCII Shibe. wow """ if self.ns.no_shibe: return [''] with open(self.doge_path) as f: if sys.version_info < (3, 0): if locale.getpreferredencoding() == 'UTF-8': doge_lin...
python
def load_doge(self): """ Return pretty ASCII Shibe. wow """ if self.ns.no_shibe: return [''] with open(self.doge_path) as f: if sys.version_info < (3, 0): if locale.getpreferredencoding() == 'UTF-8': doge_lin...
[ "def", "load_doge", "(", "self", ")", ":", "if", "self", ".", "ns", ".", "no_shibe", ":", "return", "[", "''", "]", "with", "open", "(", "self", ".", "doge_path", ")", "as", "f", ":", "if", "sys", ".", "version_info", "<", "(", "3", ",", "0", "...
Return pretty ASCII Shibe. wow
[ "Return", "pretty", "ASCII", "Shibe", "." ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L140-L167
train
thiderman/doge
doge/core.py
Doge.get_real_data
def get_real_data(self): """ Grab actual data from the system """ ret = [] username = os.environ.get('USER') if username: ret.append(username) editor = os.environ.get('EDITOR') if editor: editor = editor.split('/')[-1] ...
python
def get_real_data(self): """ Grab actual data from the system """ ret = [] username = os.environ.get('USER') if username: ret.append(username) editor = os.environ.get('EDITOR') if editor: editor = editor.split('/')[-1] ...
[ "def", "get_real_data", "(", "self", ")", ":", "ret", "=", "[", "]", "username", "=", "os", ".", "environ", ".", "get", "(", "'USER'", ")", "if", "username", ":", "ret", ".", "append", "(", "username", ")", "editor", "=", "os", ".", "environ", ".",...
Grab actual data from the system
[ "Grab", "actual", "data", "from", "the", "system" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L169-L207
train
thiderman/doge
doge/core.py
Doge.get_stdin_data
def get_stdin_data(self): """ Get words from stdin. """ if self.tty.in_is_tty: # No pipez found return False if sys.version_info < (3, 0): stdin_lines = (l.decode('utf-8') for l in sys.stdin.xreadlines()) else: stdin_line...
python
def get_stdin_data(self): """ Get words from stdin. """ if self.tty.in_is_tty: # No pipez found return False if sys.version_info < (3, 0): stdin_lines = (l.decode('utf-8') for l in sys.stdin.xreadlines()) else: stdin_line...
[ "def", "get_stdin_data", "(", "self", ")", ":", "if", "self", ".", "tty", ".", "in_is_tty", ":", "return", "False", "if", "sys", ".", "version_info", "<", "(", "3", ",", "0", ")", ":", "stdin_lines", "=", "(", "l", ".", "decode", "(", "'utf-8'", ")...
Get words from stdin.
[ "Get", "words", "from", "stdin", "." ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L213-L242
train
thiderman/doge
doge/core.py
Doge.get_processes
def get_processes(self): """ Grab a shuffled list of all currently running process names """ procs = set() try: # POSIX ps, so it should work in most environments where doge would p = sp.Popen(['ps', '-A', '-o', 'comm='], stdout=sp.PIPE) out...
python
def get_processes(self): """ Grab a shuffled list of all currently running process names """ procs = set() try: # POSIX ps, so it should work in most environments where doge would p = sp.Popen(['ps', '-A', '-o', 'comm='], stdout=sp.PIPE) out...
[ "def", "get_processes", "(", "self", ")", ":", "procs", "=", "set", "(", ")", "try", ":", "p", "=", "sp", ".", "Popen", "(", "[", "'ps'", ",", "'-A'", ",", "'-o'", ",", "'comm='", "]", ",", "stdout", "=", "sp", ".", "PIPE", ")", "output", ",", ...
Grab a shuffled list of all currently running process names
[ "Grab", "a", "shuffled", "list", "of", "all", "currently", "running", "process", "names" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L244-L270
train
thiderman/doge
doge/core.py
TTYHandler.get_tty_size
def get_tty_size(self): """ Get the current terminal size without using a subprocess http://stackoverflow.com/questions/566746 I have no clue what-so-fucking ever over how this works or why it returns the size of the terminal in both cells and pixels. But hey, it does. ...
python
def get_tty_size(self): """ Get the current terminal size without using a subprocess http://stackoverflow.com/questions/566746 I have no clue what-so-fucking ever over how this works or why it returns the size of the terminal in both cells and pixels. But hey, it does. ...
[ "def", "get_tty_size", "(", "self", ")", ":", "if", "sys", ".", "platform", "==", "'win32'", ":", "ret", "=", "self", ".", "_tty_size_windows", "(", "-", "10", ")", "ret", "=", "ret", "or", "self", ".", "_tty_size_windows", "(", "-", "11", ")", "ret"...
Get the current terminal size without using a subprocess http://stackoverflow.com/questions/566746 I have no clue what-so-fucking ever over how this works or why it returns the size of the terminal in both cells and pixels. But hey, it does.
[ "Get", "the", "current", "terminal", "size", "without", "using", "a", "subprocess" ]
cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f
https://github.com/thiderman/doge/blob/cea077d4f72929f9dcf44d0d16a7d1a6ee0e3e3f/doge/core.py#L365-L386
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
_coords
def _coords(shape): """ Return a list of lists of coordinates of the polygon. The list consists firstly of the list of exterior coordinates followed by zero or more lists of any interior coordinates. """ assert shape.geom_type == 'Polygon' coords = [list(shape.exterior.coords)] for inte...
python
def _coords(shape): """ Return a list of lists of coordinates of the polygon. The list consists firstly of the list of exterior coordinates followed by zero or more lists of any interior coordinates. """ assert shape.geom_type == 'Polygon' coords = [list(shape.exterior.coords)] for inte...
[ "def", "_coords", "(", "shape", ")", ":", "assert", "shape", ".", "geom_type", "==", "'Polygon'", "coords", "=", "[", "list", "(", "shape", ".", "exterior", ".", "coords", ")", "]", "for", "interior", "in", "shape", ".", "interiors", ":", "coords", "."...
Return a list of lists of coordinates of the polygon. The list consists firstly of the list of exterior coordinates followed by zero or more lists of any interior coordinates.
[ "Return", "a", "list", "of", "lists", "of", "coordinates", "of", "the", "polygon", ".", "The", "list", "consists", "firstly", "of", "the", "list", "of", "exterior", "coordinates", "followed", "by", "zero", "or", "more", "lists", "of", "any", "interior", "c...
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L8-L19
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
_union_in_blocks
def _union_in_blocks(contours, block_size): """ Generator which yields a valid shape for each block_size multiple of input contours. This merges together the contours for each block before yielding them. """ n_contours = len(contours) for i in range(0, n_contours, block_size): j = m...
python
def _union_in_blocks(contours, block_size): """ Generator which yields a valid shape for each block_size multiple of input contours. This merges together the contours for each block before yielding them. """ n_contours = len(contours) for i in range(0, n_contours, block_size): j = m...
[ "def", "_union_in_blocks", "(", "contours", ",", "block_size", ")", ":", "n_contours", "=", "len", "(", "contours", ")", "for", "i", "in", "range", "(", "0", ",", "n_contours", ",", "block_size", ")", ":", "j", "=", "min", "(", "i", "+", "block_size", ...
Generator which yields a valid shape for each block_size multiple of input contours. This merges together the contours for each block before yielding them.
[ "Generator", "which", "yields", "a", "valid", "shape", "for", "each", "block_size", "multiple", "of", "input", "contours", ".", "This", "merges", "together", "the", "contours", "for", "each", "block", "before", "yielding", "them", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L53-L74
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
_polytree_node_to_shapely
def _polytree_node_to_shapely(node): """ Recurses down a Clipper PolyTree, extracting the results as Shapely objects. Returns a tuple of (list of polygons, list of children) """ polygons = [] children = [] for ch in node.Childs: p, c = _polytree_node_to_shapely(ch) poly...
python
def _polytree_node_to_shapely(node): """ Recurses down a Clipper PolyTree, extracting the results as Shapely objects. Returns a tuple of (list of polygons, list of children) """ polygons = [] children = [] for ch in node.Childs: p, c = _polytree_node_to_shapely(ch) poly...
[ "def", "_polytree_node_to_shapely", "(", "node", ")", ":", "polygons", "=", "[", "]", "children", "=", "[", "]", "for", "ch", "in", "node", ".", "Childs", ":", "p", ",", "c", "=", "_polytree_node_to_shapely", "(", "ch", ")", "polygons", ".", "extend", ...
Recurses down a Clipper PolyTree, extracting the results as Shapely objects. Returns a tuple of (list of polygons, list of children)
[ "Recurses", "down", "a", "Clipper", "PolyTree", "extracting", "the", "results", "as", "Shapely", "objects", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L87-L169
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
make_valid_pyclipper
def make_valid_pyclipper(shape): """ Use the pyclipper library to "union" a polygon on its own. This operation uses the even-odd rule to determine which points are in the interior of the polygon, and can reconstruct the orientation of the polygon from that. The pyclipper library is robust, and uses ...
python
def make_valid_pyclipper(shape): """ Use the pyclipper library to "union" a polygon on its own. This operation uses the even-odd rule to determine which points are in the interior of the polygon, and can reconstruct the orientation of the polygon from that. The pyclipper library is robust, and uses ...
[ "def", "make_valid_pyclipper", "(", "shape", ")", ":", "clean_shape", "=", "_drop_degenerate_inners", "(", "shape", ")", "pc", "=", "pyclipper", ".", "Pyclipper", "(", ")", "try", ":", "pc", ".", "AddPaths", "(", "_coords", "(", "clean_shape", ")", ",", "p...
Use the pyclipper library to "union" a polygon on its own. This operation uses the even-odd rule to determine which points are in the interior of the polygon, and can reconstruct the orientation of the polygon from that. The pyclipper library is robust, and uses integer coordinates, so should not produc...
[ "Use", "the", "pyclipper", "library", "to", "union", "a", "polygon", "on", "its", "own", ".", "This", "operation", "uses", "the", "even", "-", "odd", "rule", "to", "determine", "which", "points", "are", "in", "the", "interior", "of", "the", "polygon", "a...
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L184-L211
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
make_valid_polygon
def make_valid_polygon(shape): """ Make a polygon valid. Polygons can be invalid in many ways, such as self-intersection, self-touching and degeneracy. This process attempts to make a polygon valid while retaining as much of its extent or area as possible. First, we call pyclipper to robustly u...
python
def make_valid_polygon(shape): """ Make a polygon valid. Polygons can be invalid in many ways, such as self-intersection, self-touching and degeneracy. This process attempts to make a polygon valid while retaining as much of its extent or area as possible. First, we call pyclipper to robustly u...
[ "def", "make_valid_polygon", "(", "shape", ")", ":", "assert", "shape", ".", "geom_type", "==", "'Polygon'", "shape", "=", "make_valid_pyclipper", "(", "shape", ")", "assert", "shape", ".", "is_valid", "return", "shape" ]
Make a polygon valid. Polygons can be invalid in many ways, such as self-intersection, self-touching and degeneracy. This process attempts to make a polygon valid while retaining as much of its extent or area as possible. First, we call pyclipper to robustly union the polygon. Using this on its own...
[ "Make", "a", "polygon", "valid", ".", "Polygons", "can", "be", "invalid", "in", "many", "ways", "such", "as", "self", "-", "intersection", "self", "-", "touching", "and", "degeneracy", ".", "This", "process", "attempts", "to", "make", "a", "polygon", "vali...
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L214-L234
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/polygon.py
make_it_valid
def make_it_valid(shape): """ Attempt to make any polygon or multipolygon valid. """ if shape.is_empty: return shape elif shape.type == 'MultiPolygon': shape = make_valid_multipolygon(shape) elif shape.type == 'Polygon': shape = make_valid_polygon(shape) return sh...
python
def make_it_valid(shape): """ Attempt to make any polygon or multipolygon valid. """ if shape.is_empty: return shape elif shape.type == 'MultiPolygon': shape = make_valid_multipolygon(shape) elif shape.type == 'Polygon': shape = make_valid_polygon(shape) return sh...
[ "def", "make_it_valid", "(", "shape", ")", ":", "if", "shape", ".", "is_empty", ":", "return", "shape", "elif", "shape", ".", "type", "==", "'MultiPolygon'", ":", "shape", "=", "make_valid_multipolygon", "(", "shape", ")", "elif", "shape", ".", "type", "==...
Attempt to make any polygon or multipolygon valid.
[ "Attempt", "to", "make", "any", "polygon", "or", "multipolygon", "valid", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/polygon.py#L254-L268
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/optimise.py
_decode_lines
def _decode_lines(geom): """ Decode a linear MVT geometry into a list of Lines. Each individual linestring in the MVT is extracted to a separate entry in the list of lines. """ lines = [] current_line = [] current_moveto = None # to keep track of the position. we'll adapt the move...
python
def _decode_lines(geom): """ Decode a linear MVT geometry into a list of Lines. Each individual linestring in the MVT is extracted to a separate entry in the list of lines. """ lines = [] current_line = [] current_moveto = None # to keep track of the position. we'll adapt the move...
[ "def", "_decode_lines", "(", "geom", ")", ":", "lines", "=", "[", "]", "current_line", "=", "[", "]", "current_moveto", "=", "None", "x", "=", "0", "y", "=", "0", "end", "=", "len", "(", "geom", ")", "i", "=", "0", "while", "i", "<", "end", ":"...
Decode a linear MVT geometry into a list of Lines. Each individual linestring in the MVT is extracted to a separate entry in the list of lines.
[ "Decode", "a", "linear", "MVT", "geometry", "into", "a", "list", "of", "Lines", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/optimise.py#L85-L146
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/optimise.py
_reorder_lines
def _reorder_lines(lines): """ Reorder lines so that the distance from the end of one to the beginning of the next is minimised. """ x = 0 y = 0 new_lines = [] # treat the list of lines as a stack, off which we keep popping the best # one to add next. while lines: # loo...
python
def _reorder_lines(lines): """ Reorder lines so that the distance from the end of one to the beginning of the next is minimised. """ x = 0 y = 0 new_lines = [] # treat the list of lines as a stack, off which we keep popping the best # one to add next. while lines: # loo...
[ "def", "_reorder_lines", "(", "lines", ")", ":", "x", "=", "0", "y", "=", "0", "new_lines", "=", "[", "]", "while", "lines", ":", "min_dist", "=", "None", "min_i", "=", "None", "for", "i", ",", "line", "in", "enumerate", "(", "lines", ")", ":", "...
Reorder lines so that the distance from the end of one to the beginning of the next is minimised.
[ "Reorder", "lines", "so", "that", "the", "distance", "from", "the", "end", "of", "one", "to", "the", "beginning", "of", "the", "next", "is", "minimised", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/optimise.py#L149-L182
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/optimise.py
_rewrite_geometry
def _rewrite_geometry(geom, new_lines): """ Re-encode a list of Lines with absolute MoveTos as a continuous stream of MVT geometry commands, each relative to the last. Replace geom with that stream. """ new_geom = [] x = 0 y = 0 for line in new_lines: moveto, endsat, lineto_...
python
def _rewrite_geometry(geom, new_lines): """ Re-encode a list of Lines with absolute MoveTos as a continuous stream of MVT geometry commands, each relative to the last. Replace geom with that stream. """ new_geom = [] x = 0 y = 0 for line in new_lines: moveto, endsat, lineto_...
[ "def", "_rewrite_geometry", "(", "geom", ",", "new_lines", ")", ":", "new_geom", "=", "[", "]", "x", "=", "0", "y", "=", "0", "for", "line", "in", "new_lines", ":", "moveto", ",", "endsat", ",", "lineto_cmds", "=", "line", "dx", "=", "moveto", ".", ...
Re-encode a list of Lines with absolute MoveTos as a continuous stream of MVT geometry commands, each relative to the last. Replace geom with that stream.
[ "Re", "-", "encode", "a", "list", "of", "Lines", "with", "absolute", "MoveTos", "as", "a", "continuous", "stream", "of", "MVT", "geometry", "commands", "each", "relative", "to", "the", "last", ".", "Replace", "geom", "with", "that", "stream", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/optimise.py#L185-L210
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/optimise.py
optimise_tile
def optimise_tile(tile_bytes): """ Decode a sequence of bytes as an MVT tile and reorder the string table of its layers and the order of its multilinestrings to save a few bytes. """ t = tile() t.ParseFromString(tile_bytes) for layer in t.layers: sto = StringTableOptimiser() ...
python
def optimise_tile(tile_bytes): """ Decode a sequence of bytes as an MVT tile and reorder the string table of its layers and the order of its multilinestrings to save a few bytes. """ t = tile() t.ParseFromString(tile_bytes) for layer in t.layers: sto = StringTableOptimiser() ...
[ "def", "optimise_tile", "(", "tile_bytes", ")", ":", "t", "=", "tile", "(", ")", "t", ".", "ParseFromString", "(", "tile_bytes", ")", "for", "layer", "in", "t", ".", "layers", ":", "sto", "=", "StringTableOptimiser", "(", ")", "for", "feature", "in", "...
Decode a sequence of bytes as an MVT tile and reorder the string table of its layers and the order of its multilinestrings to save a few bytes.
[ "Decode", "a", "sequence", "of", "bytes", "as", "an", "MVT", "tile", "and", "reorder", "the", "string", "table", "of", "its", "layers", "and", "the", "order", "of", "its", "multilinestrings", "to", "save", "a", "few", "bytes", "." ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/optimise.py#L226-L247
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/geom_encoder.py
GeometryEncoder.coords_on_grid
def coords_on_grid(self, x, y): """ Snap coordinates on the grid with integer coordinates """ if isinstance(x, float): x = int(self._round(x)) if isinstance(y, float): y = int(self._round(y)) if not self._y_coord_down: y = self._extents - y re...
python
def coords_on_grid(self, x, y): """ Snap coordinates on the grid with integer coordinates """ if isinstance(x, float): x = int(self._round(x)) if isinstance(y, float): y = int(self._round(y)) if not self._y_coord_down: y = self._extents - y re...
[ "def", "coords_on_grid", "(", "self", ",", "x", ",", "y", ")", ":", "if", "isinstance", "(", "x", ",", "float", ")", ":", "x", "=", "int", "(", "self", ".", "_round", "(", "x", ")", ")", "if", "isinstance", "(", "y", ",", "float", ")", ":", "...
Snap coordinates on the grid with integer coordinates
[ "Snap", "coordinates", "on", "the", "grid", "with", "integer", "coordinates" ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/geom_encoder.py#L39-L48
train
tilezen/mapbox-vector-tile
mapbox_vector_tile/geom_encoder.py
GeometryEncoder.encode_arc
def encode_arc(self, coords): """ Appends commands to _geometry to create an arc. - Returns False if nothing was added - Returns True and moves _last_x, _last_y if some points where added """ last_x, last_y = self._last_x, self._last_y float_x, flo...
python
def encode_arc(self, coords): """ Appends commands to _geometry to create an arc. - Returns False if nothing was added - Returns True and moves _last_x, _last_y if some points where added """ last_x, last_y = self._last_x, self._last_y float_x, flo...
[ "def", "encode_arc", "(", "self", ",", "coords", ")", ":", "last_x", ",", "last_y", "=", "self", ".", "_last_x", ",", "self", ".", "_last_y", "float_x", ",", "float_y", "=", "next", "(", "coords", ")", "x", ",", "y", "=", "self", ".", "coords_on_grid...
Appends commands to _geometry to create an arc. - Returns False if nothing was added - Returns True and moves _last_x, _last_y if some points where added
[ "Appends", "commands", "to", "_geometry", "to", "create", "an", "arc", ".", "-", "Returns", "False", "if", "nothing", "was", "added", "-", "Returns", "True", "and", "moves", "_last_x", "_last_y", "if", "some", "points", "where", "added" ]
7327b8cff0aa2de1d5233e556bf00429ba2126a0
https://github.com/tilezen/mapbox-vector-tile/blob/7327b8cff0aa2de1d5233e556bf00429ba2126a0/mapbox_vector_tile/geom_encoder.py#L63-L96
train
thesharp/daemonize
daemonize.py
Daemonize.sigterm
def sigterm(self, signum, frame): """ These actions will be done after SIGTERM. """ self.logger.warning("Caught signal %s. Stopping daemon." % signum) sys.exit(0)
python
def sigterm(self, signum, frame): """ These actions will be done after SIGTERM. """ self.logger.warning("Caught signal %s. Stopping daemon." % signum) sys.exit(0)
[ "def", "sigterm", "(", "self", ",", "signum", ",", "frame", ")", ":", "self", ".", "logger", ".", "warning", "(", "\"Caught signal %s. Stopping daemon.\"", "%", "signum", ")", "sys", ".", "exit", "(", "0", ")" ]
These actions will be done after SIGTERM.
[ "These", "actions", "will", "be", "done", "after", "SIGTERM", "." ]
39a880f74c1d8ea09fa44fe2b99dec1c961201a9
https://github.com/thesharp/daemonize/blob/39a880f74c1d8ea09fa44fe2b99dec1c961201a9/daemonize.py#L59-L64
train
thesharp/daemonize
daemonize.py
Daemonize.exit
def exit(self): """ Cleanup pid file at exit. """ self.logger.warning("Stopping daemon.") os.remove(self.pid) sys.exit(0)
python
def exit(self): """ Cleanup pid file at exit. """ self.logger.warning("Stopping daemon.") os.remove(self.pid) sys.exit(0)
[ "def", "exit", "(", "self", ")", ":", "self", ".", "logger", ".", "warning", "(", "\"Stopping daemon.\"", ")", "os", ".", "remove", "(", "self", ".", "pid", ")", "sys", ".", "exit", "(", "0", ")" ]
Cleanup pid file at exit.
[ "Cleanup", "pid", "file", "at", "exit", "." ]
39a880f74c1d8ea09fa44fe2b99dec1c961201a9
https://github.com/thesharp/daemonize/blob/39a880f74c1d8ea09fa44fe2b99dec1c961201a9/daemonize.py#L66-L72
train
ierror/django-js-reverse
django_js_reverse/templatetags/js_reverse.py
js_reverse_inline
def js_reverse_inline(context): """ Outputs a string of javascript that can generate URLs via the use of the names given to those URLs. """ if 'request' in context: default_urlresolver = get_resolver(getattr(context['request'], 'urlconf', None)) else: default_urlresolver = get_re...
python
def js_reverse_inline(context): """ Outputs a string of javascript that can generate URLs via the use of the names given to those URLs. """ if 'request' in context: default_urlresolver = get_resolver(getattr(context['request'], 'urlconf', None)) else: default_urlresolver = get_re...
[ "def", "js_reverse_inline", "(", "context", ")", ":", "if", "'request'", "in", "context", ":", "default_urlresolver", "=", "get_resolver", "(", "getattr", "(", "context", "[", "'request'", "]", ",", "'urlconf'", ",", "None", ")", ")", "else", ":", "default_u...
Outputs a string of javascript that can generate URLs via the use of the names given to those URLs.
[ "Outputs", "a", "string", "of", "javascript", "that", "can", "generate", "URLs", "via", "the", "use", "of", "the", "names", "given", "to", "those", "URLs", "." ]
58320a8acec040636e8ad718754c2d472d0d504d
https://github.com/ierror/django-js-reverse/blob/58320a8acec040636e8ad718754c2d472d0d504d/django_js_reverse/templatetags/js_reverse.py#L16-L25
train
webrecorder/warcio
warcio/archiveiterator.py
ArchiveIterator._iterate_records
def _iterate_records(self): """ iterate over each record """ raise_invalid_gzip = False empty_record = False while True: try: self.record = self._next_record(self.next_line) if raise_invalid_gzip: self._raise_invali...
python
def _iterate_records(self): """ iterate over each record """ raise_invalid_gzip = False empty_record = False while True: try: self.record = self._next_record(self.next_line) if raise_invalid_gzip: self._raise_invali...
[ "def", "_iterate_records", "(", "self", ")", ":", "raise_invalid_gzip", "=", "False", "empty_record", "=", "False", "while", "True", ":", "try", ":", "self", ".", "record", "=", "self", ".", "_next_record", "(", "self", ".", "next_line", ")", "if", "raise_...
iterate over each record
[ "iterate", "over", "each", "record" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/archiveiterator.py#L80-L118
train
webrecorder/warcio
warcio/archiveiterator.py
ArchiveIterator._consume_blanklines
def _consume_blanklines(self): """ Consume blank lines that are between records - For warcs, there are usually 2 - For arcs, may be 1 or 0 - For block gzipped files, these are at end of each gzip envelope and are included in record length which is the full gzip envelope ...
python
def _consume_blanklines(self): """ Consume blank lines that are between records - For warcs, there are usually 2 - For arcs, may be 1 or 0 - For block gzipped files, these are at end of each gzip envelope and are included in record length which is the full gzip envelope ...
[ "def", "_consume_blanklines", "(", "self", ")", ":", "empty_size", "=", "0", "first_line", "=", "True", "while", "True", ":", "line", "=", "self", ".", "reader", ".", "readline", "(", ")", "if", "len", "(", "line", ")", "==", "0", ":", "return", "Non...
Consume blank lines that are between records - For warcs, there are usually 2 - For arcs, may be 1 or 0 - For block gzipped files, these are at end of each gzip envelope and are included in record length which is the full gzip envelope - For uncompressed, they are between recor...
[ "Consume", "blank", "lines", "that", "are", "between", "records", "-", "For", "warcs", "there", "are", "usually", "2", "-", "For", "arcs", "may", "be", "1", "or", "0", "-", "For", "block", "gzipped", "files", "these", "are", "at", "end", "of", "each", ...
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/archiveiterator.py#L133-L171
train
webrecorder/warcio
warcio/archiveiterator.py
ArchiveIterator.read_to_end
def read_to_end(self, record=None): """ Read remainder of the stream If a digester is included, update it with the data read """ # no current record to read if not self.record: return None # already at end of this record, don't read until it is consu...
python
def read_to_end(self, record=None): """ Read remainder of the stream If a digester is included, update it with the data read """ # no current record to read if not self.record: return None # already at end of this record, don't read until it is consu...
[ "def", "read_to_end", "(", "self", ",", "record", "=", "None", ")", ":", "if", "not", "self", ".", "record", ":", "return", "None", "if", "self", ".", "member_info", ":", "return", "None", "curr_offset", "=", "self", ".", "offset", "while", "True", ":"...
Read remainder of the stream If a digester is included, update it with the data read
[ "Read", "remainder", "of", "the", "stream", "If", "a", "digester", "is", "included", "update", "it", "with", "the", "data", "read" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/archiveiterator.py#L173-L215
train
webrecorder/warcio
warcio/archiveiterator.py
ArchiveIterator._next_record
def _next_record(self, next_line): """ Use loader to parse the record from the reader stream Supporting warc and arc records """ record = self.loader.parse_record_stream(self.reader, next_line, ...
python
def _next_record(self, next_line): """ Use loader to parse the record from the reader stream Supporting warc and arc records """ record = self.loader.parse_record_stream(self.reader, next_line, ...
[ "def", "_next_record", "(", "self", ",", "next_line", ")", ":", "record", "=", "self", ".", "loader", ".", "parse_record_stream", "(", "self", ".", "reader", ",", "next_line", ",", "self", ".", "known_format", ",", "self", ".", "no_record_parse", ",", "sel...
Use loader to parse the record from the reader stream Supporting warc and arc records
[ "Use", "loader", "to", "parse", "the", "record", "from", "the", "reader", "stream", "Supporting", "warc", "and", "arc", "records" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/archiveiterator.py#L231-L247
train
webrecorder/warcio
warcio/limitreader.py
LimitReader.wrap_stream
def wrap_stream(stream, content_length): """ If given content_length is an int > 0, wrap the stream in a LimitReader. Otherwise, return the stream unaltered """ try: content_length = int(content_length) if content_length >= 0: # optimize: i...
python
def wrap_stream(stream, content_length): """ If given content_length is an int > 0, wrap the stream in a LimitReader. Otherwise, return the stream unaltered """ try: content_length = int(content_length) if content_length >= 0: # optimize: i...
[ "def", "wrap_stream", "(", "stream", ",", "content_length", ")", ":", "try", ":", "content_length", "=", "int", "(", "content_length", ")", "if", "content_length", ">=", "0", ":", "if", "isinstance", "(", "stream", ",", "LimitReader", ")", ":", "stream", "...
If given content_length is an int > 0, wrap the stream in a LimitReader. Otherwise, return the stream unaltered
[ "If", "given", "content_length", "is", "an", "int", ">", "0", "wrap", "the", "stream", "in", "a", "LimitReader", ".", "Otherwise", "return", "the", "stream", "unaltered" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/limitreader.py#L50-L68
train
webrecorder/warcio
warcio/statusandheaders.py
StatusAndHeaders.replace_header
def replace_header(self, name, value): """ replace header with new value or add new header return old header value, if any """ name_lower = name.lower() for index in range(len(self.headers) - 1, -1, -1): curr_name, curr_value = self.headers[index] ...
python
def replace_header(self, name, value): """ replace header with new value or add new header return old header value, if any """ name_lower = name.lower() for index in range(len(self.headers) - 1, -1, -1): curr_name, curr_value = self.headers[index] ...
[ "def", "replace_header", "(", "self", ",", "name", ",", "value", ")", ":", "name_lower", "=", "name", ".", "lower", "(", ")", "for", "index", "in", "range", "(", "len", "(", "self", ".", "headers", ")", "-", "1", ",", "-", "1", ",", "-", "1", "...
replace header with new value or add new header return old header value, if any
[ "replace", "header", "with", "new", "value", "or", "add", "new", "header", "return", "old", "header", "value", "if", "any" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/statusandheaders.py#L49-L62
train
webrecorder/warcio
warcio/statusandheaders.py
StatusAndHeaders.validate_statusline
def validate_statusline(self, valid_statusline): """ Check that the statusline is valid, eg. starts with a numeric code. If not, replace with passed in valid_statusline """ code = self.get_statuscode() try: code = int(code) assert(code > 0) ...
python
def validate_statusline(self, valid_statusline): """ Check that the statusline is valid, eg. starts with a numeric code. If not, replace with passed in valid_statusline """ code = self.get_statuscode() try: code = int(code) assert(code > 0) ...
[ "def", "validate_statusline", "(", "self", ",", "valid_statusline", ")", ":", "code", "=", "self", ".", "get_statuscode", "(", ")", "try", ":", "code", "=", "int", "(", "code", ")", "assert", "(", "code", ">", "0", ")", "return", "True", "except", "(",...
Check that the statusline is valid, eg. starts with a numeric code. If not, replace with passed in valid_statusline
[ "Check", "that", "the", "statusline", "is", "valid", "eg", ".", "starts", "with", "a", "numeric", "code", ".", "If", "not", "replace", "with", "passed", "in", "valid_statusline" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/statusandheaders.py#L85-L97
train
webrecorder/warcio
warcio/statusandheaders.py
StatusAndHeaders.add_range
def add_range(self, start, part_len, total_len): """ Add range headers indicating that this a partial response """ content_range = 'bytes {0}-{1}/{2}'.format(start, start + part_len - 1, ...
python
def add_range(self, start, part_len, total_len): """ Add range headers indicating that this a partial response """ content_range = 'bytes {0}-{1}/{2}'.format(start, start + part_len - 1, ...
[ "def", "add_range", "(", "self", ",", "start", ",", "part_len", ",", "total_len", ")", ":", "content_range", "=", "'bytes {0}-{1}/{2}'", ".", "format", "(", "start", ",", "start", "+", "part_len", "-", "1", ",", "total_len", ")", "self", ".", "statusline",...
Add range headers indicating that this a partial response
[ "Add", "range", "headers", "indicating", "that", "this", "a", "partial", "response" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/statusandheaders.py#L99-L111
train
webrecorder/warcio
warcio/statusandheaders.py
StatusAndHeadersParser.parse
def parse(self, stream, full_statusline=None): """ parse stream for status line and headers return a StatusAndHeaders object support continuation headers starting with space or tab """ # status line w newlines intact if full_statusline is None: full_...
python
def parse(self, stream, full_statusline=None): """ parse stream for status line and headers return a StatusAndHeaders object support continuation headers starting with space or tab """ # status line w newlines intact if full_statusline is None: full_...
[ "def", "parse", "(", "self", ",", "stream", ",", "full_statusline", "=", "None", ")", ":", "if", "full_statusline", "is", "None", ":", "full_statusline", "=", "stream", ".", "readline", "(", ")", "full_statusline", "=", "self", ".", "decode_header", "(", "...
parse stream for status line and headers return a StatusAndHeaders object support continuation headers starting with space or tab
[ "parse", "stream", "for", "status", "line", "and", "headers", "return", "a", "StatusAndHeaders", "object" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/statusandheaders.py#L223-L295
train
webrecorder/warcio
warcio/statusandheaders.py
StatusAndHeadersParser.split_prefix
def split_prefix(key, prefixs): """ split key string into prefix and remainder for first matching prefix from a list """ key_upper = key.upper() for prefix in prefixs: if key_upper.startswith(prefix): plen = len(prefix) return (...
python
def split_prefix(key, prefixs): """ split key string into prefix and remainder for first matching prefix from a list """ key_upper = key.upper() for prefix in prefixs: if key_upper.startswith(prefix): plen = len(prefix) return (...
[ "def", "split_prefix", "(", "key", ",", "prefixs", ")", ":", "key_upper", "=", "key", ".", "upper", "(", ")", "for", "prefix", "in", "prefixs", ":", "if", "key_upper", ".", "startswith", "(", "prefix", ")", ":", "plen", "=", "len", "(", "prefix", ")"...
split key string into prefix and remainder for first matching prefix from a list
[ "split", "key", "string", "into", "prefix", "and", "remainder", "for", "first", "matching", "prefix", "from", "a", "list" ]
c64c4394805e13256695f51af072c95389397ee9
https://github.com/webrecorder/warcio/blob/c64c4394805e13256695f51af072c95389397ee9/warcio/statusandheaders.py#L298-L307
train
nickjj/ansigenome
ansigenome/config.py
Config.ask_questions
def ask_questions(self): """ Obtain config settings from the user. """ out_config = {} for key in c.CONFIG_QUESTIONS: section = key[1] print for question in section: answer = utils.ask(question[1], question[2]) ...
python
def ask_questions(self): """ Obtain config settings from the user. """ out_config = {} for key in c.CONFIG_QUESTIONS: section = key[1] print for question in section: answer = utils.ask(question[1], question[2]) ...
[ "def", "ask_questions", "(", "self", ")", ":", "out_config", "=", "{", "}", "for", "key", "in", "c", ".", "CONFIG_QUESTIONS", ":", "section", "=", "key", "[", "1", "]", "print", "for", "question", "in", "section", ":", "answer", "=", "utils", ".", "a...
Obtain config settings from the user.
[ "Obtain", "config", "settings", "from", "the", "user", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/config.py#L45-L83
train
nickjj/ansigenome
ansigenome/ui.py
log
def log(color, *args): """ Print a message with a specific color. """ if color in c.LOG_COLOR.keys(): out_color = c.LOG_COLOR[color] else: out_color = color for arg in args: print clr.stringc(arg, out_color)
python
def log(color, *args): """ Print a message with a specific color. """ if color in c.LOG_COLOR.keys(): out_color = c.LOG_COLOR[color] else: out_color = color for arg in args: print clr.stringc(arg, out_color)
[ "def", "log", "(", "color", ",", "*", "args", ")", ":", "if", "color", "in", "c", ".", "LOG_COLOR", ".", "keys", "(", ")", ":", "out_color", "=", "c", ".", "LOG_COLOR", "[", "color", "]", "else", ":", "out_color", "=", "color", "for", "arg", "in"...
Print a message with a specific color.
[ "Print", "a", "message", "with", "a", "specific", "color", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L5-L15
train
nickjj/ansigenome
ansigenome/ui.py
usage
def usage(): """ Return the usage for the help command. """ l_bracket = clr.stringc("[", "dark gray") r_bracket = clr.stringc("]", "dark gray") pipe = clr.stringc("|", "dark gray") app_name = clr.stringc("%prog", "bright blue") commands = clr.stringc("{0}".format(pipe).join(c.VALID_ACTI...
python
def usage(): """ Return the usage for the help command. """ l_bracket = clr.stringc("[", "dark gray") r_bracket = clr.stringc("]", "dark gray") pipe = clr.stringc("|", "dark gray") app_name = clr.stringc("%prog", "bright blue") commands = clr.stringc("{0}".format(pipe).join(c.VALID_ACTI...
[ "def", "usage", "(", ")", ":", "l_bracket", "=", "clr", ".", "stringc", "(", "\"[\"", ",", "\"dark gray\"", ")", "r_bracket", "=", "clr", ".", "stringc", "(", "\"]\"", ",", "\"dark gray\"", ")", "pipe", "=", "clr", ".", "stringc", "(", "\"|\"", ",", ...
Return the usage for the help command.
[ "Return", "the", "usage", "for", "the", "help", "command", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L39-L66
train
nickjj/ansigenome
ansigenome/ui.py
epilogue
def epilogue(app_name): """ Return the epilogue for the help command. """ app_name = clr.stringc(app_name, "bright blue") command = clr.stringc("command", "cyan") help = clr.stringc("--help", "green") return "\n%s %s %s for more info on a command\n" % (app_name, ...
python
def epilogue(app_name): """ Return the epilogue for the help command. """ app_name = clr.stringc(app_name, "bright blue") command = clr.stringc("command", "cyan") help = clr.stringc("--help", "green") return "\n%s %s %s for more info on a command\n" % (app_name, ...
[ "def", "epilogue", "(", "app_name", ")", ":", "app_name", "=", "clr", ".", "stringc", "(", "app_name", ",", "\"bright blue\"", ")", "command", "=", "clr", ".", "stringc", "(", "\"command\"", ",", "\"cyan\"", ")", "help", "=", "clr", ".", "stringc", "(", ...
Return the epilogue for the help command.
[ "Return", "the", "epilogue", "for", "the", "help", "command", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L69-L78
train
nickjj/ansigenome
ansigenome/ui.py
command_name
def command_name(app_name, command, help_text): """ Return a snippet of help text for this command. """ command = clr.stringc(command, "cyan") help = clr.stringc("--help", "green") return "{0} {1} {2}\n{3}\n\n".format(app_name, command, help, help_text)
python
def command_name(app_name, command, help_text): """ Return a snippet of help text for this command. """ command = clr.stringc(command, "cyan") help = clr.stringc("--help", "green") return "{0} {1} {2}\n{3}\n\n".format(app_name, command, help, help_text)
[ "def", "command_name", "(", "app_name", ",", "command", ",", "help_text", ")", ":", "command", "=", "clr", ".", "stringc", "(", "command", ",", "\"cyan\"", ")", "help", "=", "clr", ".", "stringc", "(", "\"--help\"", ",", "\"green\"", ")", "return", "\"{0...
Return a snippet of help text for this command.
[ "Return", "a", "snippet", "of", "help", "text", "for", "this", "command", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L81-L89
train
nickjj/ansigenome
ansigenome/ui.py
role
def role(name, report, role_name_length): """ Print the role information. """ pad_role_name_by = 11 + role_name_length defaults = field_value(report["total_defaults"], "defaults", "blue", 16) facts = field_value(report["total_facts"], "facts", "purple", 16) files = field_value(report["total...
python
def role(name, report, role_name_length): """ Print the role information. """ pad_role_name_by = 11 + role_name_length defaults = field_value(report["total_defaults"], "defaults", "blue", 16) facts = field_value(report["total_facts"], "facts", "purple", 16) files = field_value(report["total...
[ "def", "role", "(", "name", ",", "report", ",", "role_name_length", ")", ":", "pad_role_name_by", "=", "11", "+", "role_name_length", "defaults", "=", "field_value", "(", "report", "[", "\"total_defaults\"", "]", ",", "\"defaults\"", ",", "\"blue\"", ",", "16"...
Print the role information.
[ "Print", "the", "role", "information", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L92-L105
train
nickjj/ansigenome
ansigenome/ui.py
field_value
def field_value(key, label, color, padding): """ Print a specific field's stats. """ if not clr.has_colors and padding > 0: padding = 7 if color == "bright gray" or color == "dark gray": bright_prefix = "" else: bright_prefix = "bright " field = clr.stringc(key, "{0...
python
def field_value(key, label, color, padding): """ Print a specific field's stats. """ if not clr.has_colors and padding > 0: padding = 7 if color == "bright gray" or color == "dark gray": bright_prefix = "" else: bright_prefix = "bright " field = clr.stringc(key, "{0...
[ "def", "field_value", "(", "key", ",", "label", ",", "color", ",", "padding", ")", ":", "if", "not", "clr", ".", "has_colors", "and", "padding", ">", "0", ":", "padding", "=", "7", "if", "color", "==", "\"bright gray\"", "or", "color", "==", "\"dark gr...
Print a specific field's stats.
[ "Print", "a", "specific", "field", "s", "stats", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L108-L123
train
nickjj/ansigenome
ansigenome/ui.py
totals
def totals(report, total_roles, role_name_length): """ Print the totals for each role's stats. """ roles_len_string = len(str(total_roles)) roles_label_len = 6 # "r" "o" "l" "e" "s" " " if clr.has_colors: roles_count_offset = 22 else: roles_count_offset = 13 roles_coun...
python
def totals(report, total_roles, role_name_length): """ Print the totals for each role's stats. """ roles_len_string = len(str(total_roles)) roles_label_len = 6 # "r" "o" "l" "e" "s" " " if clr.has_colors: roles_count_offset = 22 else: roles_count_offset = 13 roles_coun...
[ "def", "totals", "(", "report", ",", "total_roles", ",", "role_name_length", ")", ":", "roles_len_string", "=", "len", "(", "str", "(", "total_roles", ")", ")", "roles_label_len", "=", "6", "if", "clr", ".", "has_colors", ":", "roles_count_offset", "=", "22"...
Print the totals for each role's stats.
[ "Print", "the", "totals", "for", "each", "role", "s", "stats", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L126-L155
train
nickjj/ansigenome
ansigenome/ui.py
gen_totals
def gen_totals(report, file_type): """ Print the gen totals. """ label = clr.stringc(file_type + " files ", "bright purple") ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0) skipped = field_value(report["skipped_role"], "skipped", c.LOG_COLOR["skipped"...
python
def gen_totals(report, file_type): """ Print the gen totals. """ label = clr.stringc(file_type + " files ", "bright purple") ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0) skipped = field_value(report["skipped_role"], "skipped", c.LOG_COLOR["skipped"...
[ "def", "gen_totals", "(", "report", ",", "file_type", ")", ":", "label", "=", "clr", ".", "stringc", "(", "file_type", "+", "\" files \"", ",", "\"bright purple\"", ")", "ok", "=", "field_value", "(", "report", "[", "\"ok_role\"", "]", ",", "\"ok\"", ","...
Print the gen totals.
[ "Print", "the", "gen", "totals", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L158-L176
train
nickjj/ansigenome
ansigenome/ui.py
scan_totals
def scan_totals(report): """ Print the scan totals. """ ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0) missing_readme = field_value(report["missing_readme_role"], "missing readme(s)", c.LOG_COLOR["missing_readme"], 16...
python
def scan_totals(report): """ Print the scan totals. """ ok = field_value(report["ok_role"], "ok", c.LOG_COLOR["ok"], 0) missing_readme = field_value(report["missing_readme_role"], "missing readme(s)", c.LOG_COLOR["missing_readme"], 16...
[ "def", "scan_totals", "(", "report", ")", ":", "ok", "=", "field_value", "(", "report", "[", "\"ok_role\"", "]", ",", "\"ok\"", ",", "c", ".", "LOG_COLOR", "[", "\"ok\"", "]", ",", "0", ")", "missing_readme", "=", "field_value", "(", "report", "[", "\"...
Print the scan totals.
[ "Print", "the", "scan", "totals", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/ui.py#L179-L192
train
nickjj/ansigenome
ansigenome/color.py
has_colors
def has_colors(stream): """ Determine if the terminal supports ansi colors. """ if not hasattr(stream, "isatty"): return False if not stream.isatty(): return False # auto color only on TTYs try: import curses curses.setupterm() return curses.tigetnum("col...
python
def has_colors(stream): """ Determine if the terminal supports ansi colors. """ if not hasattr(stream, "isatty"): return False if not stream.isatty(): return False # auto color only on TTYs try: import curses curses.setupterm() return curses.tigetnum("col...
[ "def", "has_colors", "(", "stream", ")", ":", "if", "not", "hasattr", "(", "stream", ",", "\"isatty\"", ")", ":", "return", "False", "if", "not", "stream", ".", "isatty", "(", ")", ":", "return", "False", "try", ":", "import", "curses", "curses", ".", ...
Determine if the terminal supports ansi colors.
[ "Determine", "if", "the", "terminal", "supports", "ansi", "colors", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/color.py#L4-L17
train
nickjj/ansigenome
ansigenome/color.py
stringc
def stringc(text, color): """ Return a string with terminal colors. """ if has_colors: text = str(text) return "\033["+codeCodes[color]+"m"+text+"\033[0m" else: return text
python
def stringc(text, color): """ Return a string with terminal colors. """ if has_colors: text = str(text) return "\033["+codeCodes[color]+"m"+text+"\033[0m" else: return text
[ "def", "stringc", "(", "text", ",", "color", ")", ":", "if", "has_colors", ":", "text", "=", "str", "(", "text", ")", "return", "\"\\033[\"", "+", "codeCodes", "[", "color", "]", "+", "\"m\"", "+", "text", "+", "\"\\033[0m\"", "else", ":", "return", ...
Return a string with terminal colors.
[ "Return", "a", "string", "with", "terminal", "colors", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/color.py#L47-L56
train
nickjj/ansigenome
ansigenome/run.py
Run.execute_command
def execute_command(self): """ Execute the shell command. """ stderr = "" role_count = 0 for role in utils.roles_dict(self.roles_path): self.command = self.command.replace("%role_name", role) (_, err) = utils.capture_shell("cd {0} && {1}". ...
python
def execute_command(self): """ Execute the shell command. """ stderr = "" role_count = 0 for role in utils.roles_dict(self.roles_path): self.command = self.command.replace("%role_name", role) (_, err) = utils.capture_shell("cd {0} && {1}". ...
[ "def", "execute_command", "(", "self", ")", ":", "stderr", "=", "\"\"", "role_count", "=", "0", "for", "role", "in", "utils", ".", "roles_dict", "(", "self", ".", "roles_path", ")", ":", "self", ".", "command", "=", "self", ".", "command", ".", "replac...
Execute the shell command.
[ "Execute", "the", "shell", "command", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/run.py#L17-L40
train
nickjj/ansigenome
ansigenome/utils.py
mkdir_p
def mkdir_p(path): """ Emulate the behavior of mkdir -p. """ try: os.makedirs(path) except OSError as err: if err.errno == errno.EEXIST and os.path.isdir(path): pass else: ui.error(c.MESSAGES["path_unmakable"], err) sys.exit(1)
python
def mkdir_p(path): """ Emulate the behavior of mkdir -p. """ try: os.makedirs(path) except OSError as err: if err.errno == errno.EEXIST and os.path.isdir(path): pass else: ui.error(c.MESSAGES["path_unmakable"], err) sys.exit(1)
[ "def", "mkdir_p", "(", "path", ")", ":", "try", ":", "os", ".", "makedirs", "(", "path", ")", "except", "OSError", "as", "err", ":", "if", "err", ".", "errno", "==", "errno", ".", "EEXIST", "and", "os", ".", "path", ".", "isdir", "(", "path", ")"...
Emulate the behavior of mkdir -p.
[ "Emulate", "the", "behavior", "of", "mkdir", "-", "p", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L35-L46
train
nickjj/ansigenome
ansigenome/utils.py
string_to_file
def string_to_file(path, input): """ Write a file from a given string. """ mkdir_p(os.path.dirname(path)) with codecs.open(path, "w+", "UTF-8") as file: file.write(input)
python
def string_to_file(path, input): """ Write a file from a given string. """ mkdir_p(os.path.dirname(path)) with codecs.open(path, "w+", "UTF-8") as file: file.write(input)
[ "def", "string_to_file", "(", "path", ",", "input", ")", ":", "mkdir_p", "(", "os", ".", "path", ".", "dirname", "(", "path", ")", ")", "with", "codecs", ".", "open", "(", "path", ",", "\"w+\"", ",", "\"UTF-8\"", ")", "as", "file", ":", "file", "."...
Write a file from a given string.
[ "Write", "a", "file", "from", "a", "given", "string", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L49-L56
train
nickjj/ansigenome
ansigenome/utils.py
file_to_string
def file_to_string(path): """ Return the contents of a file when given a path. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1) with codecs.open(path, "r", "UTF-8") as contents: return contents.read()
python
def file_to_string(path): """ Return the contents of a file when given a path. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1) with codecs.open(path, "r", "UTF-8") as contents: return contents.read()
[ "def", "file_to_string", "(", "path", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "ui", ".", "error", "(", "c", ".", "MESSAGES", "[", "\"path_missing\"", "]", ",", "path", ")", "sys", ".", "exit", "(", "1", ")"...
Return the contents of a file when given a path.
[ "Return", "the", "contents", "of", "a", "file", "when", "given", "a", "path", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L59-L68
train
nickjj/ansigenome
ansigenome/utils.py
file_to_list
def file_to_list(path): """ Return the contents of a file as a list when given a path. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1) with codecs.open(path, "r", "UTF-8") as contents: lines = contents.read().splitlines() return l...
python
def file_to_list(path): """ Return the contents of a file as a list when given a path. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1) with codecs.open(path, "r", "UTF-8") as contents: lines = contents.read().splitlines() return l...
[ "def", "file_to_list", "(", "path", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "ui", ".", "error", "(", "c", ".", "MESSAGES", "[", "\"path_missing\"", "]", ",", "path", ")", "sys", ".", "exit", "(", "1", ")", ...
Return the contents of a file as a list when given a path.
[ "Return", "the", "contents", "of", "a", "file", "as", "a", "list", "when", "given", "a", "path", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L71-L82
train
nickjj/ansigenome
ansigenome/utils.py
url_to_string
def url_to_string(url): """ Return the contents of a web site url as a string. """ try: page = urllib2.urlopen(url) except (urllib2.HTTPError, urllib2.URLError) as err: ui.error(c.MESSAGES["url_unreachable"], err) sys.exit(1) return page
python
def url_to_string(url): """ Return the contents of a web site url as a string. """ try: page = urllib2.urlopen(url) except (urllib2.HTTPError, urllib2.URLError) as err: ui.error(c.MESSAGES["url_unreachable"], err) sys.exit(1) return page
[ "def", "url_to_string", "(", "url", ")", ":", "try", ":", "page", "=", "urllib2", ".", "urlopen", "(", "url", ")", "except", "(", "urllib2", ".", "HTTPError", ",", "urllib2", ".", "URLError", ")", "as", "err", ":", "ui", ".", "error", "(", "c", "."...
Return the contents of a web site url as a string.
[ "Return", "the", "contents", "of", "a", "web", "site", "url", "as", "a", "string", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L92-L102
train
nickjj/ansigenome
ansigenome/utils.py
template
def template(path, extend_path, out): """ Return a jinja2 template instance with extends support. """ files = [] # add the "extender" template when it exists if len(extend_path) > 0: # determine the base readme path base_path = os.path.dirname(extend_path) new_base_path ...
python
def template(path, extend_path, out): """ Return a jinja2 template instance with extends support. """ files = [] # add the "extender" template when it exists if len(extend_path) > 0: # determine the base readme path base_path = os.path.dirname(extend_path) new_base_path ...
[ "def", "template", "(", "path", ",", "extend_path", ",", "out", ")", ":", "files", "=", "[", "]", "if", "len", "(", "extend_path", ")", ">", "0", ":", "base_path", "=", "os", ".", "path", ".", "dirname", "(", "extend_path", ")", "new_base_path", "=",...
Return a jinja2 template instance with extends support.
[ "Return", "a", "jinja2", "template", "instance", "with", "extends", "support", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L105-L167
train
nickjj/ansigenome
ansigenome/utils.py
files_in_path
def files_in_path(path): """ Return a list of all files in a path but exclude git folders. """ aggregated_files = [] for dir_, _, files in os.walk(path): for file in files: relative_dir = os.path.relpath(dir_, path) if ".git" not in relative_dir: rel...
python
def files_in_path(path): """ Return a list of all files in a path but exclude git folders. """ aggregated_files = [] for dir_, _, files in os.walk(path): for file in files: relative_dir = os.path.relpath(dir_, path) if ".git" not in relative_dir: rel...
[ "def", "files_in_path", "(", "path", ")", ":", "aggregated_files", "=", "[", "]", "for", "dir_", ",", "_", ",", "files", "in", "os", ".", "walk", "(", "path", ")", ":", "for", "file", "in", "files", ":", "relative_dir", "=", "os", ".", "path", ".",...
Return a list of all files in a path but exclude git folders.
[ "Return", "a", "list", "of", "all", "files", "in", "a", "path", "but", "exclude", "git", "folders", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L170-L184
train
nickjj/ansigenome
ansigenome/utils.py
exit_if_path_not_found
def exit_if_path_not_found(path): """ Exit if the path is not found. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1)
python
def exit_if_path_not_found(path): """ Exit if the path is not found. """ if not os.path.exists(path): ui.error(c.MESSAGES["path_missing"], path) sys.exit(1)
[ "def", "exit_if_path_not_found", "(", "path", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "ui", ".", "error", "(", "c", ".", "MESSAGES", "[", "\"path_missing\"", "]", ",", "path", ")", "sys", ".", "exit", "(", "1...
Exit if the path is not found.
[ "Exit", "if", "the", "path", "is", "not", "found", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L187-L193
train
nickjj/ansigenome
ansigenome/utils.py
yaml_load
def yaml_load(path, input="", err_quit=False): """ Return a yaml dict from a file or string with error handling. """ try: if len(input) > 0: return yaml.safe_load(input) elif len(path) > 0: return yaml.safe_load(file_to_string(path)) except Exception as err: ...
python
def yaml_load(path, input="", err_quit=False): """ Return a yaml dict from a file or string with error handling. """ try: if len(input) > 0: return yaml.safe_load(input) elif len(path) > 0: return yaml.safe_load(file_to_string(path)) except Exception as err: ...
[ "def", "yaml_load", "(", "path", ",", "input", "=", "\"\"", ",", "err_quit", "=", "False", ")", ":", "try", ":", "if", "len", "(", "input", ")", ">", "0", ":", "return", "yaml", ".", "safe_load", "(", "input", ")", "elif", "len", "(", "path", ")"...
Return a yaml dict from a file or string with error handling.
[ "Return", "a", "yaml", "dict", "from", "a", "file", "or", "string", "with", "error", "handling", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L209-L227
train
nickjj/ansigenome
ansigenome/utils.py
to_nice_yaml
def to_nice_yaml(yaml_input, indentation=2): """ Return condensed yaml into human readable yaml. """ return yaml.safe_dump(yaml_input, indent=indentation, allow_unicode=True, default_flow_style=False)
python
def to_nice_yaml(yaml_input, indentation=2): """ Return condensed yaml into human readable yaml. """ return yaml.safe_dump(yaml_input, indent=indentation, allow_unicode=True, default_flow_style=False)
[ "def", "to_nice_yaml", "(", "yaml_input", ",", "indentation", "=", "2", ")", ":", "return", "yaml", ".", "safe_dump", "(", "yaml_input", ",", "indent", "=", "indentation", ",", "allow_unicode", "=", "True", ",", "default_flow_style", "=", "False", ")" ]
Return condensed yaml into human readable yaml.
[ "Return", "condensed", "yaml", "into", "human", "readable", "yaml", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L230-L235
train
nickjj/ansigenome
ansigenome/utils.py
keys_in_dict
def keys_in_dict(d, parent_key, keys): """ Create a list of keys from a dict recursively. """ for key, value in d.iteritems(): if isinstance(value, dict): keys_in_dict(value, key, keys) else: if parent_key: prefix = parent_key + "." els...
python
def keys_in_dict(d, parent_key, keys): """ Create a list of keys from a dict recursively. """ for key, value in d.iteritems(): if isinstance(value, dict): keys_in_dict(value, key, keys) else: if parent_key: prefix = parent_key + "." els...
[ "def", "keys_in_dict", "(", "d", ",", "parent_key", ",", "keys", ")", ":", "for", "key", ",", "value", "in", "d", ".", "iteritems", "(", ")", ":", "if", "isinstance", "(", "value", ",", "dict", ")", ":", "keys_in_dict", "(", "value", ",", "key", ",...
Create a list of keys from a dict recursively.
[ "Create", "a", "list", "of", "keys", "from", "a", "dict", "recursively", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L258-L273
train
nickjj/ansigenome
ansigenome/utils.py
swap_yaml_string
def swap_yaml_string(file_path, swaps): """ Swap a string in a yaml file without touching the existing formatting. """ original_file = file_to_string(file_path) new_file = original_file changed = False for item in swaps: match = re.compile(r'(?<={0}: )(["\']?)(.*)\1'.format(item[0])...
python
def swap_yaml_string(file_path, swaps): """ Swap a string in a yaml file without touching the existing formatting. """ original_file = file_to_string(file_path) new_file = original_file changed = False for item in swaps: match = re.compile(r'(?<={0}: )(["\']?)(.*)\1'.format(item[0])...
[ "def", "swap_yaml_string", "(", "file_path", ",", "swaps", ")", ":", "original_file", "=", "file_to_string", "(", "file_path", ")", "new_file", "=", "original_file", "changed", "=", "False", "for", "item", "in", "swaps", ":", "match", "=", "re", ".", "compil...
Swap a string in a yaml file without touching the existing formatting.
[ "Swap", "a", "string", "in", "a", "yaml", "file", "without", "touching", "the", "existing", "formatting", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L276-L295
train
nickjj/ansigenome
ansigenome/utils.py
exit_if_no_roles
def exit_if_no_roles(roles_count, roles_path): """ Exit if there were no roles found. """ if roles_count == 0: ui.warn(c.MESSAGES["empty_roles_path"], roles_path) sys.exit()
python
def exit_if_no_roles(roles_count, roles_path): """ Exit if there were no roles found. """ if roles_count == 0: ui.warn(c.MESSAGES["empty_roles_path"], roles_path) sys.exit()
[ "def", "exit_if_no_roles", "(", "roles_count", ",", "roles_path", ")", ":", "if", "roles_count", "==", "0", ":", "ui", ".", "warn", "(", "c", ".", "MESSAGES", "[", "\"empty_roles_path\"", "]", ",", "roles_path", ")", "sys", ".", "exit", "(", ")" ]
Exit if there were no roles found.
[ "Exit", "if", "there", "were", "no", "roles", "found", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L303-L309
train
nickjj/ansigenome
ansigenome/utils.py
roles_dict
def roles_dict(path, repo_prefix="", repo_sub_dir=""): """ Return a dict of role names and repo paths. """ exit_if_path_not_found(path) aggregated_roles = {} roles = os.walk(path).next()[1] # First scan all directories for role in roles: for sub_role in roles_dict(path + "/" +...
python
def roles_dict(path, repo_prefix="", repo_sub_dir=""): """ Return a dict of role names and repo paths. """ exit_if_path_not_found(path) aggregated_roles = {} roles = os.walk(path).next()[1] # First scan all directories for role in roles: for sub_role in roles_dict(path + "/" +...
[ "def", "roles_dict", "(", "path", ",", "repo_prefix", "=", "\"\"", ",", "repo_sub_dir", "=", "\"\"", ")", ":", "exit_if_path_not_found", "(", "path", ")", "aggregated_roles", "=", "{", "}", "roles", "=", "os", ".", "walk", "(", "path", ")", ".", "next", ...
Return a dict of role names and repo paths.
[ "Return", "a", "dict", "of", "role", "names", "and", "repo", "paths", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L312-L336
train
nickjj/ansigenome
ansigenome/utils.py
is_role
def is_role(path): """ Determine if a path is an ansible role. """ seems_legit = False for folder in c.ANSIBLE_FOLDERS: if os.path.exists(os.path.join(path, folder)): seems_legit = True return seems_legit
python
def is_role(path): """ Determine if a path is an ansible role. """ seems_legit = False for folder in c.ANSIBLE_FOLDERS: if os.path.exists(os.path.join(path, folder)): seems_legit = True return seems_legit
[ "def", "is_role", "(", "path", ")", ":", "seems_legit", "=", "False", "for", "folder", "in", "c", ".", "ANSIBLE_FOLDERS", ":", "if", "os", ".", "path", ".", "exists", "(", "os", ".", "path", ".", "join", "(", "path", ",", "folder", ")", ")", ":", ...
Determine if a path is an ansible role.
[ "Determine", "if", "a", "path", "is", "an", "ansible", "role", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L349-L358
train
nickjj/ansigenome
ansigenome/utils.py
stripped_args
def stripped_args(args): """ Return the stripped version of the arguments. """ stripped_args = [] for arg in args: stripped_args.append(arg.strip()) return stripped_args
python
def stripped_args(args): """ Return the stripped version of the arguments. """ stripped_args = [] for arg in args: stripped_args.append(arg.strip()) return stripped_args
[ "def", "stripped_args", "(", "args", ")", ":", "stripped_args", "=", "[", "]", "for", "arg", "in", "args", ":", "stripped_args", ".", "append", "(", "arg", ".", "strip", "(", ")", ")", "return", "stripped_args" ]
Return the stripped version of the arguments.
[ "Return", "the", "stripped", "version", "of", "the", "arguments", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L361-L369
train
nickjj/ansigenome
ansigenome/utils.py
normalize_role
def normalize_role(role, config): """ Normalize a role name. """ if role.startswith(config["scm_repo_prefix"]): role_name = role.replace(config["scm_repo_prefix"], "") else: if "." in role: galaxy_prefix = "{0}.".format(config["scm_user"]) role_name = role.rep...
python
def normalize_role(role, config): """ Normalize a role name. """ if role.startswith(config["scm_repo_prefix"]): role_name = role.replace(config["scm_repo_prefix"], "") else: if "." in role: galaxy_prefix = "{0}.".format(config["scm_user"]) role_name = role.rep...
[ "def", "normalize_role", "(", "role", ",", "config", ")", ":", "if", "role", ".", "startswith", "(", "config", "[", "\"scm_repo_prefix\"", "]", ")", ":", "role_name", "=", "role", ".", "replace", "(", "config", "[", "\"scm_repo_prefix\"", "]", ",", "\"\"",...
Normalize a role name.
[ "Normalize", "a", "role", "name", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L372-L387
train
nickjj/ansigenome
ansigenome/utils.py
create_meta_main
def create_meta_main(create_path, config, role, categories): """ Create a meta template. """ meta_file = c.DEFAULT_META_FILE.replace( "%author_name", config["author_name"]) meta_file = meta_file.replace( "%author_company", config["author_company"]) meta_file = meta_file.replace("...
python
def create_meta_main(create_path, config, role, categories): """ Create a meta template. """ meta_file = c.DEFAULT_META_FILE.replace( "%author_name", config["author_name"]) meta_file = meta_file.replace( "%author_company", config["author_company"]) meta_file = meta_file.replace("...
[ "def", "create_meta_main", "(", "create_path", ",", "config", ",", "role", ",", "categories", ")", ":", "meta_file", "=", "c", ".", "DEFAULT_META_FILE", ".", "replace", "(", "\"%author_name\"", ",", "config", "[", "\"author_name\"", "]", ")", "meta_file", "=",...
Create a meta template.
[ "Create", "a", "meta", "template", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L390-L407
train
nickjj/ansigenome
ansigenome/utils.py
get_version
def get_version(path, default="master"): """ Return the version from a VERSION file """ version = default if os.path.exists(path): version_contents = file_to_string(path) if version_contents: version = version_contents.strip() return version
python
def get_version(path, default="master"): """ Return the version from a VERSION file """ version = default if os.path.exists(path): version_contents = file_to_string(path) if version_contents: version = version_contents.strip() return version
[ "def", "get_version", "(", "path", ",", "default", "=", "\"master\"", ")", ":", "version", "=", "default", "if", "os", ".", "path", ".", "exists", "(", "path", ")", ":", "version_contents", "=", "file_to_string", "(", "path", ")", "if", "version_contents",...
Return the version from a VERSION file
[ "Return", "the", "version", "from", "a", "VERSION", "file" ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L410-L420
train
nickjj/ansigenome
ansigenome/utils.py
write_config
def write_config(path, config): """ Write the config with a little post-converting formatting. """ config_as_string = to_nice_yaml(config) config_as_string = "---\n" + config_as_string string_to_file(path, config_as_string)
python
def write_config(path, config): """ Write the config with a little post-converting formatting. """ config_as_string = to_nice_yaml(config) config_as_string = "---\n" + config_as_string string_to_file(path, config_as_string)
[ "def", "write_config", "(", "path", ",", "config", ")", ":", "config_as_string", "=", "to_nice_yaml", "(", "config", ")", "config_as_string", "=", "\"---\\n\"", "+", "config_as_string", "string_to_file", "(", "path", ",", "config_as_string", ")" ]
Write the config with a little post-converting formatting.
[ "Write", "the", "config", "with", "a", "little", "post", "-", "converting", "formatting", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/utils.py#L423-L431
train
nickjj/ansigenome
ansigenome/scan.py
Scan.limit_roles
def limit_roles(self): """ Limit the roles being scanned. """ new_roles = {} roles = self.options.limit.split(",") for key, value in self.roles.iteritems(): for role in roles: role = role.strip() if key == role: ...
python
def limit_roles(self): """ Limit the roles being scanned. """ new_roles = {} roles = self.options.limit.split(",") for key, value in self.roles.iteritems(): for role in roles: role = role.strip() if key == role: ...
[ "def", "limit_roles", "(", "self", ")", ":", "new_roles", "=", "{", "}", "roles", "=", "self", ".", "options", ".", "limit", ".", "split", "(", "\",\"", ")", "for", "key", ",", "value", "in", "self", ".", "roles", ".", "iteritems", "(", ")", ":", ...
Limit the roles being scanned.
[ "Limit", "the", "roles", "being", "scanned", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L88-L101
train
nickjj/ansigenome
ansigenome/scan.py
Scan.scan_roles
def scan_roles(self): """ Iterate over each role and report its stats. """ for key, value in sorted(self.roles.iteritems()): self.paths["role"] = os.path.join(self.roles_path, key) self.paths["meta"] = os.path.join(self.paths["role"], "meta", ...
python
def scan_roles(self): """ Iterate over each role and report its stats. """ for key, value in sorted(self.roles.iteritems()): self.paths["role"] = os.path.join(self.roles_path, key) self.paths["meta"] = os.path.join(self.paths["role"], "meta", ...
[ "def", "scan_roles", "(", "self", ")", ":", "for", "key", ",", "value", "in", "sorted", "(", "self", ".", "roles", ".", "iteritems", "(", ")", ")", ":", "self", ".", "paths", "[", "\"role\"", "]", "=", "os", ".", "path", ".", "join", "(", "self",...
Iterate over each role and report its stats.
[ "Iterate", "over", "each", "role", "and", "report", "its", "stats", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L103-L155
train
nickjj/ansigenome
ansigenome/scan.py
Scan.export_roles
def export_roles(self): """ Export the roles to one of the export types. """ # prepare the report by removing unnecessary fields del self.report["state"] del self.report["stats"] for role in self.report["roles"]: del self.report["roles"][role]["state"]...
python
def export_roles(self): """ Export the roles to one of the export types. """ # prepare the report by removing unnecessary fields del self.report["state"] del self.report["stats"] for role in self.report["roles"]: del self.report["roles"][role]["state"]...
[ "def", "export_roles", "(", "self", ")", ":", "del", "self", ".", "report", "[", "\"state\"", "]", "del", "self", ".", "report", "[", "\"stats\"", "]", "for", "role", "in", "self", ".", "report", "[", "\"roles\"", "]", ":", "del", "self", ".", "repor...
Export the roles to one of the export types.
[ "Export", "the", "roles", "to", "one", "of", "the", "export", "types", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L157-L174
train
nickjj/ansigenome
ansigenome/scan.py
Scan.report_role
def report_role(self, role): """ Return the fields gathered. """ self.yaml_files = [] fields = { "state": "skipped", "total_files": self.gather_files(), "total_lines": self.gather_lines(), "total_facts": self.gather_facts(), ...
python
def report_role(self, role): """ Return the fields gathered. """ self.yaml_files = [] fields = { "state": "skipped", "total_files": self.gather_files(), "total_lines": self.gather_lines(), "total_facts": self.gather_facts(), ...
[ "def", "report_role", "(", "self", ",", "role", ")", ":", "self", ".", "yaml_files", "=", "[", "]", "fields", "=", "{", "\"state\"", ":", "\"skipped\"", ",", "\"total_files\"", ":", "self", ".", "gather_files", "(", ")", ",", "\"total_lines\"", ":", "sel...
Return the fields gathered.
[ "Return", "the", "fields", "gathered", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L176-L196
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_meta
def gather_meta(self): """ Return the meta file. """ if not os.path.exists(self.paths["meta"]): return "" meta_dict = utils.yaml_load(self.paths["meta"]) # gather the dependencies if meta_dict and "dependencies" in meta_dict: # create a s...
python
def gather_meta(self): """ Return the meta file. """ if not os.path.exists(self.paths["meta"]): return "" meta_dict = utils.yaml_load(self.paths["meta"]) # gather the dependencies if meta_dict and "dependencies" in meta_dict: # create a s...
[ "def", "gather_meta", "(", "self", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "\"meta\"", "]", ")", ":", "return", "\"\"", "meta_dict", "=", "utils", ".", "yaml_load", "(", "self", ".", "paths", "[", "\...
Return the meta file.
[ "Return", "the", "meta", "file", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L198-L225
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_readme
def gather_readme(self): """ Return the readme file. """ if not os.path.exists(self.paths["readme"]): return "" return utils.file_to_string(self.paths["readme"])
python
def gather_readme(self): """ Return the readme file. """ if not os.path.exists(self.paths["readme"]): return "" return utils.file_to_string(self.paths["readme"])
[ "def", "gather_readme", "(", "self", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "\"readme\"", "]", ")", ":", "return", "\"\"", "return", "utils", ".", "file_to_string", "(", "self", ".", "paths", "[", "\"...
Return the readme file.
[ "Return", "the", "readme", "file", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L227-L234
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_defaults
def gather_defaults(self): """ Return the number of default variables. """ total_defaults = 0 defaults_lines = [] if not os.path.exists(self.paths["defaults"]): # reset the defaults if no defaults were found self.defaults = "" return 0...
python
def gather_defaults(self): """ Return the number of default variables. """ total_defaults = 0 defaults_lines = [] if not os.path.exists(self.paths["defaults"]): # reset the defaults if no defaults were found self.defaults = "" return 0...
[ "def", "gather_defaults", "(", "self", ")", ":", "total_defaults", "=", "0", "defaults_lines", "=", "[", "]", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "\"defaults\"", "]", ")", ":", "self", ".", "defaults", "=", ...
Return the number of default variables.
[ "Return", "the", "number", "of", "default", "variables", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L236-L267
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_facts
def gather_facts(self): """ Return the number of facts. """ facts = [] for file in self.yaml_files: facts += self.gather_facts_list(file) unique_facts = list(set(facts)) self.facts = unique_facts return len(unique_facts)
python
def gather_facts(self): """ Return the number of facts. """ facts = [] for file in self.yaml_files: facts += self.gather_facts_list(file) unique_facts = list(set(facts)) self.facts = unique_facts return len(unique_facts)
[ "def", "gather_facts", "(", "self", ")", ":", "facts", "=", "[", "]", "for", "file", "in", "self", ".", "yaml_files", ":", "facts", "+=", "self", ".", "gather_facts_list", "(", "file", ")", "unique_facts", "=", "list", "(", "set", "(", "facts", ")", ...
Return the number of facts.
[ "Return", "the", "number", "of", "facts", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L269-L281
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_facts_list
def gather_facts_list(self, file): """ Return a list of facts. """ facts = [] contents = utils.file_to_string(os.path.join(self.paths["role"], file)) contents = re.sub(r"\s+", "", contents) matches = self.regex_facts.findal...
python
def gather_facts_list(self, file): """ Return a list of facts. """ facts = [] contents = utils.file_to_string(os.path.join(self.paths["role"], file)) contents = re.sub(r"\s+", "", contents) matches = self.regex_facts.findal...
[ "def", "gather_facts_list", "(", "self", ",", "file", ")", ":", "facts", "=", "[", "]", "contents", "=", "utils", ".", "file_to_string", "(", "os", ".", "path", ".", "join", "(", "self", ".", "paths", "[", "\"role\"", "]", ",", "file", ")", ")", "c...
Return a list of facts.
[ "Return", "a", "list", "of", "facts", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L283-L297
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_files
def gather_files(self): """ Return the number of files. """ self.all_files = utils.files_in_path(self.paths["role"]) return len(self.all_files)
python
def gather_files(self): """ Return the number of files. """ self.all_files = utils.files_in_path(self.paths["role"]) return len(self.all_files)
[ "def", "gather_files", "(", "self", ")", ":", "self", ".", "all_files", "=", "utils", ".", "files_in_path", "(", "self", ".", "paths", "[", "\"role\"", "]", ")", "return", "len", "(", "self", ".", "all_files", ")" ]
Return the number of files.
[ "Return", "the", "number", "of", "files", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L299-L305
train
nickjj/ansigenome
ansigenome/scan.py
Scan.gather_lines
def gather_lines(self): """ Return the number of lines. """ total_lines = 0 for file in self.all_files: full_path = os.path.join(self.paths["role"], file) with open(full_path, "r") as f: for line in f: total_lines += 1 ...
python
def gather_lines(self): """ Return the number of lines. """ total_lines = 0 for file in self.all_files: full_path = os.path.join(self.paths["role"], file) with open(full_path, "r") as f: for line in f: total_lines += 1 ...
[ "def", "gather_lines", "(", "self", ")", ":", "total_lines", "=", "0", "for", "file", "in", "self", ".", "all_files", ":", "full_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "paths", "[", "\"role\"", "]", ",", "file", ")", "with", ...
Return the number of lines.
[ "Return", "the", "number", "of", "lines", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L307-L322
train
nickjj/ansigenome
ansigenome/scan.py
Scan.tally_role_columns
def tally_role_columns(self): """ Sum up all of the stat columns. """ totals = self.report["totals"] roles = self.report["roles"] totals["dependencies"] = sum(roles[item] ["total_dependencies"] for item in roles) totals["defau...
python
def tally_role_columns(self): """ Sum up all of the stat columns. """ totals = self.report["totals"] roles = self.report["roles"] totals["dependencies"] = sum(roles[item] ["total_dependencies"] for item in roles) totals["defau...
[ "def", "tally_role_columns", "(", "self", ")", ":", "totals", "=", "self", ".", "report", "[", "\"totals\"", "]", "roles", "=", "self", ".", "report", "[", "\"roles\"", "]", "totals", "[", "\"dependencies\"", "]", "=", "sum", "(", "roles", "[", "item", ...
Sum up all of the stat columns.
[ "Sum", "up", "all", "of", "the", "stat", "columns", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L324-L337
train
nickjj/ansigenome
ansigenome/scan.py
Scan.valid_meta
def valid_meta(self, role): """ Return whether or not the meta file being read is valid. """ if os.path.exists(self.paths["meta"]): self.meta_dict = utils.yaml_load(self.paths["meta"]) else: self.report["state"]["missing_meta_role"] += 1 self.r...
python
def valid_meta(self, role): """ Return whether or not the meta file being read is valid. """ if os.path.exists(self.paths["meta"]): self.meta_dict = utils.yaml_load(self.paths["meta"]) else: self.report["state"]["missing_meta_role"] += 1 self.r...
[ "def", "valid_meta", "(", "self", ",", "role", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "\"meta\"", "]", ")", ":", "self", ".", "meta_dict", "=", "utils", ".", "yaml_load", "(", "self", ".", "paths", "[", ...
Return whether or not the meta file being read is valid.
[ "Return", "whether", "or", "not", "the", "meta", "file", "being", "read", "is", "valid", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L339-L358
train
nickjj/ansigenome
ansigenome/scan.py
Scan.make_or_augment_meta
def make_or_augment_meta(self, role): """ Create or augment a meta file. """ if not os.path.exists(self.paths["meta"]): utils.create_meta_main(self.paths["meta"], self.config, role, "") self.report["state"]["ok_role"] += 1 self.report["roles"][role]["s...
python
def make_or_augment_meta(self, role): """ Create or augment a meta file. """ if not os.path.exists(self.paths["meta"]): utils.create_meta_main(self.paths["meta"], self.config, role, "") self.report["state"]["ok_role"] += 1 self.report["roles"][role]["s...
[ "def", "make_or_augment_meta", "(", "self", ",", "role", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "\"meta\"", "]", ")", ":", "utils", ".", "create_meta_main", "(", "self", ".", "paths", "[", "\"meta\"", ...
Create or augment a meta file.
[ "Create", "or", "augment", "a", "meta", "file", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L360-L398
train
nickjj/ansigenome
ansigenome/scan.py
Scan.write_readme
def write_readme(self, role): """ Write out a new readme file. """ j2_out = self.readme_template.render(self.readme_template_vars) self.update_gen_report(role, "readme", j2_out)
python
def write_readme(self, role): """ Write out a new readme file. """ j2_out = self.readme_template.render(self.readme_template_vars) self.update_gen_report(role, "readme", j2_out)
[ "def", "write_readme", "(", "self", ",", "role", ")", ":", "j2_out", "=", "self", ".", "readme_template", ".", "render", "(", "self", ".", "readme_template_vars", ")", "self", ".", "update_gen_report", "(", "role", ",", "\"readme\"", ",", "j2_out", ")" ]
Write out a new readme file.
[ "Write", "out", "a", "new", "readme", "file", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L431-L437
train
nickjj/ansigenome
ansigenome/scan.py
Scan.write_meta
def write_meta(self, role): """ Write out a new meta file. """ meta_file = utils.file_to_string(self.paths["meta"]) self.update_gen_report(role, "meta", meta_file)
python
def write_meta(self, role): """ Write out a new meta file. """ meta_file = utils.file_to_string(self.paths["meta"]) self.update_gen_report(role, "meta", meta_file)
[ "def", "write_meta", "(", "self", ",", "role", ")", ":", "meta_file", "=", "utils", ".", "file_to_string", "(", "self", ".", "paths", "[", "\"meta\"", "]", ")", "self", ".", "update_gen_report", "(", "role", ",", "\"meta\"", ",", "meta_file", ")" ]
Write out a new meta file.
[ "Write", "out", "a", "new", "meta", "file", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L439-L445
train
nickjj/ansigenome
ansigenome/scan.py
Scan.update_scan_report
def update_scan_report(self, role): """ Update the role state and adjust the scan totals. """ state = self.report["state"] # ensure the missing meta state is colored up and the ok count is good if self.gendoc: if self.report["roles"][role]["state"] == "missin...
python
def update_scan_report(self, role): """ Update the role state and adjust the scan totals. """ state = self.report["state"] # ensure the missing meta state is colored up and the ok count is good if self.gendoc: if self.report["roles"][role]["state"] == "missin...
[ "def", "update_scan_report", "(", "self", ",", "role", ")", ":", "state", "=", "self", ".", "report", "[", "\"state\"", "]", "if", "self", ".", "gendoc", ":", "if", "self", ".", "report", "[", "\"roles\"", "]", "[", "role", "]", "[", "\"state\"", "]"...
Update the role state and adjust the scan totals.
[ "Update", "the", "role", "state", "and", "adjust", "the", "scan", "totals", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L447-L463
train
nickjj/ansigenome
ansigenome/scan.py
Scan.update_gen_report
def update_gen_report(self, role, file, original): """ Update the role state and adjust the gen totals. """ state = self.report["state"] if not os.path.exists(self.paths[file]): state["ok_role"] += 1 self.report["roles"][role]["state"] = "ok" elif...
python
def update_gen_report(self, role, file, original): """ Update the role state and adjust the gen totals. """ state = self.report["state"] if not os.path.exists(self.paths[file]): state["ok_role"] += 1 self.report["roles"][role]["state"] = "ok" elif...
[ "def", "update_gen_report", "(", "self", ",", "role", ",", "file", ",", "original", ")", ":", "state", "=", "self", ".", "report", "[", "\"state\"", "]", "if", "not", "os", ".", "path", ".", "exists", "(", "self", ".", "paths", "[", "file", "]", ")...
Update the role state and adjust the gen totals.
[ "Update", "the", "role", "state", "and", "adjust", "the", "gen", "totals", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L465-L483
train
nickjj/ansigenome
ansigenome/scan.py
Scan.make_meta_dict_consistent
def make_meta_dict_consistent(self): """ Remove the possibility of the main keys being undefined. """ if self.meta_dict is None: self.meta_dict = {} if "galaxy_info" not in self.meta_dict: self.meta_dict["galaxy_info"] = {} if "dependencies" not ...
python
def make_meta_dict_consistent(self): """ Remove the possibility of the main keys being undefined. """ if self.meta_dict is None: self.meta_dict = {} if "galaxy_info" not in self.meta_dict: self.meta_dict["galaxy_info"] = {} if "dependencies" not ...
[ "def", "make_meta_dict_consistent", "(", "self", ")", ":", "if", "self", ".", "meta_dict", "is", "None", ":", "self", ".", "meta_dict", "=", "{", "}", "if", "\"galaxy_info\"", "not", "in", "self", ".", "meta_dict", ":", "self", ".", "meta_dict", "[", "\"...
Remove the possibility of the main keys being undefined.
[ "Remove", "the", "possibility", "of", "the", "main", "keys", "being", "undefined", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L485-L499
train
nickjj/ansigenome
ansigenome/scan.py
Scan.set_readme_template_vars
def set_readme_template_vars(self, role, repo_name): """ Set the readme template variables. """ # normalize and expose a bunch of fields to the template authors = [] author = { "name": self.config["author_name"], "company": self.config["author_com...
python
def set_readme_template_vars(self, role, repo_name): """ Set the readme template variables. """ # normalize and expose a bunch of fields to the template authors = [] author = { "name": self.config["author_name"], "company": self.config["author_com...
[ "def", "set_readme_template_vars", "(", "self", ",", "role", ",", "repo_name", ")", ":", "authors", "=", "[", "]", "author", "=", "{", "\"name\"", ":", "self", ".", "config", "[", "\"author_name\"", "]", ",", "\"company\"", ":", "self", ".", "config", "[...
Set the readme template variables.
[ "Set", "the", "readme", "template", "variables", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/scan.py#L501-L561
train
nickjj/ansigenome
ansigenome/init.py
Init.exit_if_path_exists
def exit_if_path_exists(self): """ Exit early if the path cannot be found. """ if os.path.exists(self.output_path): ui.error(c.MESSAGES["path_exists"], self.output_path) sys.exit(1)
python
def exit_if_path_exists(self): """ Exit early if the path cannot be found. """ if os.path.exists(self.output_path): ui.error(c.MESSAGES["path_exists"], self.output_path) sys.exit(1)
[ "def", "exit_if_path_exists", "(", "self", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "self", ".", "output_path", ")", ":", "ui", ".", "error", "(", "c", ".", "MESSAGES", "[", "\"path_exists\"", "]", ",", "self", ".", "output_path", ")", ...
Exit early if the path cannot be found.
[ "Exit", "early", "if", "the", "path", "cannot", "be", "found", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/init.py#L62-L68
train
nickjj/ansigenome
ansigenome/init.py
Init.create_skeleton
def create_skeleton(self): """ Create the role's directory and file structure. """ utils.string_to_file(os.path.join(self.output_path, "VERSION"), "master\n") for folder in c.ANSIBLE_FOLDERS: create_folder_path = os.path.join(self.output_...
python
def create_skeleton(self): """ Create the role's directory and file structure. """ utils.string_to_file(os.path.join(self.output_path, "VERSION"), "master\n") for folder in c.ANSIBLE_FOLDERS: create_folder_path = os.path.join(self.output_...
[ "def", "create_skeleton", "(", "self", ")", ":", "utils", ".", "string_to_file", "(", "os", ".", "path", ".", "join", "(", "self", ".", "output_path", ",", "\"VERSION\"", ")", ",", "\"master\\n\"", ")", "for", "folder", "in", "c", ".", "ANSIBLE_FOLDERS", ...
Create the role's directory and file structure.
[ "Create", "the", "role", "s", "directory", "and", "file", "structure", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/init.py#L70-L94
train
nickjj/ansigenome
ansigenome/init.py
Init.create_travis_config
def create_travis_config(self): """ Create a travis test setup. """ test_runner = self.config["options_test_runner"] role_url = "{0}".format(os.path.join(self.config["scm_host"], self.config["scm_user"], ...
python
def create_travis_config(self): """ Create a travis test setup. """ test_runner = self.config["options_test_runner"] role_url = "{0}".format(os.path.join(self.config["scm_host"], self.config["scm_user"], ...
[ "def", "create_travis_config", "(", "self", ")", ":", "test_runner", "=", "self", ".", "config", "[", "\"options_test_runner\"", "]", "role_url", "=", "\"{0}\"", ".", "format", "(", "os", ".", "path", ".", "join", "(", "self", ".", "config", "[", "\"scm_ho...
Create a travis test setup.
[ "Create", "a", "travis", "test", "setup", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/init.py#L96-L115
train
nickjj/ansigenome
ansigenome/export.py
Export.set_format
def set_format(self, format): """ Pick the correct default format. """ if self.options.format: self.format = self.options.format else: self.format = \ self.config["default_format_" + format]
python
def set_format(self, format): """ Pick the correct default format. """ if self.options.format: self.format = self.options.format else: self.format = \ self.config["default_format_" + format]
[ "def", "set_format", "(", "self", ",", "format", ")", ":", "if", "self", ".", "options", ".", "format", ":", "self", ".", "format", "=", "self", ".", "options", ".", "format", "else", ":", "self", ".", "format", "=", "self", ".", "config", "[", "\"...
Pick the correct default format.
[ "Pick", "the", "correct", "default", "format", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L61-L69
train
nickjj/ansigenome
ansigenome/export.py
Export.validate_format
def validate_format(self, allowed_formats): """ Validate the allowed formats for a specific type. """ if self.format in allowed_formats: return ui.error("Export type '{0}' does not accept '{1}' format, only: " "{2}".format(self.type, self.format, all...
python
def validate_format(self, allowed_formats): """ Validate the allowed formats for a specific type. """ if self.format in allowed_formats: return ui.error("Export type '{0}' does not accept '{1}' format, only: " "{2}".format(self.type, self.format, all...
[ "def", "validate_format", "(", "self", ",", "allowed_formats", ")", ":", "if", "self", ".", "format", "in", "allowed_formats", ":", "return", "ui", ".", "error", "(", "\"Export type '{0}' does not accept '{1}' format, only: \"", "\"{2}\"", ".", "format", "(", "self"...
Validate the allowed formats for a specific type.
[ "Validate", "the", "allowed", "formats", "for", "a", "specific", "type", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L71-L80
train
nickjj/ansigenome
ansigenome/export.py
Export.graph_dot
def graph_dot(self): """ Export a graph of the data in dot format. """ default_graphviz_template = """ digraph role_dependencies { size="%size" dpi=%dpi ratio="fill" landscape=false rankdir="BT"; node [shape = "box", style = ...
python
def graph_dot(self): """ Export a graph of the data in dot format. """ default_graphviz_template = """ digraph role_dependencies { size="%size" dpi=%dpi ratio="fill" landscape=false rankdir="BT"; node [shape = "box", style = ...
[ "def", "graph_dot", "(", "self", ")", ":", "default_graphviz_template", "=", "roles_list", "=", "\"\"", "edges", "=", "\"\"", "adjusted_colors", "=", "c", ".", "X11_COLORS", "[", "125", ":", "-", "325", "]", "random", ".", "shuffle", "(", "adjusted_colors", ...
Export a graph of the data in dot format.
[ "Export", "a", "graph", "of", "the", "data", "in", "dot", "format", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L82-L161
train
nickjj/ansigenome
ansigenome/export.py
Export.exit_if_missing_graphviz
def exit_if_missing_graphviz(self): """ Detect the presence of the dot utility to make a png graph. """ (out, err) = utils.capture_shell("which dot") if "dot" not in out: ui.error(c.MESSAGES["dot_missing"])
python
def exit_if_missing_graphviz(self): """ Detect the presence of the dot utility to make a png graph. """ (out, err) = utils.capture_shell("which dot") if "dot" not in out: ui.error(c.MESSAGES["dot_missing"])
[ "def", "exit_if_missing_graphviz", "(", "self", ")", ":", "(", "out", ",", "err", ")", "=", "utils", ".", "capture_shell", "(", "\"which dot\"", ")", "if", "\"dot\"", "not", "in", "out", ":", "ui", ".", "error", "(", "c", ".", "MESSAGES", "[", "\"dot_m...
Detect the presence of the dot utility to make a png graph.
[ "Detect", "the", "presence", "of", "the", "dot", "utility", "to", "make", "a", "png", "graph", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L182-L189
train
nickjj/ansigenome
ansigenome/export.py
Export.reqs_txt
def reqs_txt(self): """ Export a requirements file in txt format. """ role_lines = "" for role in sorted(self.report["roles"]): name = utils.normalize_role(role, self.config) galaxy_name = "{0}.{1}".format(self.config["scm_user"], name) versi...
python
def reqs_txt(self): """ Export a requirements file in txt format. """ role_lines = "" for role in sorted(self.report["roles"]): name = utils.normalize_role(role, self.config) galaxy_name = "{0}.{1}".format(self.config["scm_user"], name) versi...
[ "def", "reqs_txt", "(", "self", ")", ":", "role_lines", "=", "\"\"", "for", "role", "in", "sorted", "(", "self", ".", "report", "[", "\"roles\"", "]", ")", ":", "name", "=", "utils", ".", "normalize_role", "(", "role", ",", "self", ".", "config", ")"...
Export a requirements file in txt format.
[ "Export", "a", "requirements", "file", "in", "txt", "format", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L191-L208
train
nickjj/ansigenome
ansigenome/export.py
Export.reqs_yml
def reqs_yml(self): """ Export a requirements file in yml format. """ default_yml_item = """ - src: '%src' name: '%name' scm: '%scm' version: '%version' """ role_lines = "---\n" for role in sorted(self.report["roles"]): name = utils.normalize...
python
def reqs_yml(self): """ Export a requirements file in yml format. """ default_yml_item = """ - src: '%src' name: '%name' scm: '%scm' version: '%version' """ role_lines = "---\n" for role in sorted(self.report["roles"]): name = utils.normalize...
[ "def", "reqs_yml", "(", "self", ")", ":", "default_yml_item", "=", "role_lines", "=", "\"---\\n\"", "for", "role", "in", "sorted", "(", "self", ".", "report", "[", "\"roles\"", "]", ")", ":", "name", "=", "utils", ".", "normalize_role", "(", "role", ",",...
Export a requirements file in yml format.
[ "Export", "a", "requirements", "file", "in", "yml", "format", "." ]
70cd98d7a23d36c56f4e713ea820cfb4c485c81c
https://github.com/nickjj/ansigenome/blob/70cd98d7a23d36c56f4e713ea820cfb4c485c81c/ansigenome/export.py#L210-L256
train