Python os.path.append() Examples
The following are 30
code examples of os.path.append().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os.path
, or try the search function
.
Example #1
Source File: PupyClient.py From NoobSec-Toolkit with GNU General Public License v2.0 | 7 votes |
def get_packages_path(self): """ return the list of path to search packages for depending on client OS and architecture """ path=[] if self.is_windows(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","windows","amd64")) else: path.append(os.path.join("packages","windows","x86")) path.append(os.path.join("packages","windows","all")) elif self.is_unix(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","linux","amd64")) else: path.append(os.path.join("packages","linux","x86")) path.append(os.path.join("packages","linux","all")) path.append(os.path.join("packages","all")) return path
Example #2
Source File: output.py From Pixel-Art with GNU General Public License v3.0 | 6 votes |
def draw_spline(self, drawing, splines, fill): if fill==(255,255,255): return path = [] # points = [] for spline in splines: curves = list(spline.Quadratic_Bezier_Fit()) path.append('M') path.append(self.scale_pt(curves[0][0])) for curve in curves: path.append('Q') path.append(self.scale_pt(curve[1])) path.append(self.scale_pt(curve[2])) p0 = self.scale_pt(curve[0]) p1 = self.scale_pt(curve[2]) path.append('Z') drawing.add(drawing.path(path, stroke = color(fill), fill = color(fill)))
Example #3
Source File: PupyClient.py From NoobSec-Toolkit with GNU General Public License v2.0 | 6 votes |
def get_packages_path(self): """ return the list of path to search packages for depending on client OS and architecture """ path=[] if self.is_windows(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","windows","amd64")) else: path.append(os.path.join("packages","windows","x86")) path.append(os.path.join("packages","windows","all")) elif self.is_unix(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","linux","amd64")) else: path.append(os.path.join("packages","linux","x86")) path.append(os.path.join("packages","linux","all")) path.append(os.path.join("packages","all")) return path
Example #4
Source File: glyph_image_pair.py From nototools with Apache License 2.0 | 6 votes |
def _get_cp_pairs(base_font, target_font): """Return a list of tuples of base glyph ix, target glyph ix, codepoint for all codepoints in either font. When a codepoint is in only one font, the id for the other glyph is -1.""" base_cp_map = _get_cp_to_glyphix(base_font) target_cp_map = _get_cp_to_glyphix(target_font) pairs = [] base_keys = set(base_cp_map.keys()) target_keys = set(target_cp_map.keys()) matched = base_keys & target_keys for k in sorted(matched): pairs.append((base_cp_map[k], target_cp_map[k], k)) for k in sorted(base_keys - matched): pairs.append((base_cp_map[k], -1, k)) for k in sorted(target_keys - matched): pairs.append((-1, target_cp_map[k], k)) return pairs
Example #5
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 6 votes |
def verifyNestedFileCreation(species,mod_types,ontology_type): ### Determine which mods are present for Ontology program_type,database_dir = unique.whatProgramIsThis() mods_present = []; nested_present=[]; verified = 'no' for mod in mod_types: ontology_file = database_dir+'/'+species+'/gene-go/'+mod+'-'+ontology_type+'.txt' count = verifyFileLength(ontology_file) ### See if there are lines present in the file (if present) if count>1: mods_present.append(mod) if len(mods_present)>0: for mod in mods_present: if ontology_type == 'GeneOntology': ontology_type = 'GO' ontology_file = database_dir+'/'+species+'/nested/'+mod+'_to_Nested-'+ontology_type+'.txt' count = verifyFileLength(ontology_file) ### See if there are lines present in the file (if present) if count>1: nested_present.append(mod) if len(nested_present) == len(mods_present): verified = 'yes' return verified
Example #6
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 6 votes |
def nestTree(parent_node,path,export_data,count_nodes): ### export_data,count_nodes are used for QC only children = edges[parent_node] path.append(0) for child in children.keys(): tuple_path = tuple(path) #count_nodes+=1 #try: temp = string.join(edges[child].keys(),'|') #except Exception: temp = '' #export_data.write(str(tuple_path)+'\t'+child+'\t'+temp+'\n') p = list(path) ### Otherwise, the same path somehow gets used (alternative to copy.deepcopy()) if child in edges: count_nodes = nestTree(child,p,export_data,count_nodes) #if count_nodes==1000: kill path_ontology_db[tuple_path] = child if child not in built_ontology_paths: built_ontology_paths[child] = [tuple_path] elif tuple_path not in built_ontology_paths[child]: built_ontology_paths[child].append(tuple_path) path[-1]+=1 return count_nodes
Example #7
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 6 votes |
def check_if_match(): diff = 0 bad_chars = defaultdict(list) minlen = min(len(buffers[0]), len(buffers[1])) for i in range(minlen): if buffers[0][i] != buffers[1][i]: diff += 1 bad_chars[buffers[0][i]].append(buffers[1][i]) if len(buffers[0]) > minlen: bad_chars[-1].append(buffers[1][-1]) elif len(buffers[1]) > minlen: bad_chars[-1].append(buffers[0][-1]) return (diff, bad_chars)
Example #8
Source File: PupyClient.py From backdoorme with MIT License | 6 votes |
def get_packages_path(self): """ return the list of path to search packages for depending on client OS and architecture """ path=[] if self.is_windows(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","windows","amd64")) else: path.append(os.path.join("packages","windows","x86")) path.append(os.path.join("packages","windows","all")) elif self.is_unix(): if self.is_proc_arch_64_bits(): path.append(os.path.join("packages","linux","amd64")) else: path.append(os.path.join("packages","linux","x86")) path.append(os.path.join("packages","linux","all")) path.append(os.path.join("packages","all")) return path
Example #9
Source File: graph.py From deepwalk with GNU General Public License v3.0 | 5 votes |
def random_walk(self, path_length, alpha=0, rand=random.Random(), start=None): """ Returns a truncated random walk. path_length: Length of the random walk. alpha: probability of restarts. start: the start node of the random walk. """ G = self if start: path = [start] else: # Sampling is uniform w.r.t V, and not w.r.t E path = [rand.choice(list(G.keys()))] while len(path) < path_length: cur = path[-1] if len(G[cur]) > 0: if rand.random() >= alpha: path.append(rand.choice(G[cur])) else: path.append(path[0]) else: break return [str(node) for node in path] # TODO add build_walks in here
Example #10
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 5 votes |
def swapKeyValues(db): swapped={} for key in db: values = list(db[key]) ###If the value is not a list, make a list for value in values: try: swapped[value].append(key) except KeyError: swapped[value] = [key] swapped = eliminate_redundant_dict_values(swapped) return swapped
Example #11
Source File: graph.py From deepwalk with GNU General Public License v3.0 | 5 votes |
def build_deepwalk_corpus(G, num_paths, path_length, alpha=0, rand=random.Random(0)): walks = [] nodes = list(G.nodes()) for cnt in range(num_paths): rand.shuffle(nodes) for node in nodes: walks.append(G.random_walk(path_length, rand=rand, alpha=alpha, start=node)) return walks
Example #12
Source File: graph.py From deepwalk with GNU General Public License v3.0 | 5 votes |
def load_edgelist(file_, undirected=True): G = Graph() with open(file_) as f: for l in f: x, y = l.strip().split()[:2] x = int(x) y = int(y) G[x].append(y) if undirected: G[y].append(x) G.make_consistent() return G
Example #13
Source File: graph.py From deepwalk with GNU General Public License v3.0 | 5 votes |
def from_networkx(G_input, undirected=True): G = Graph() for idx, x in enumerate(G_input.nodes()): for y in iterkeys(G_input[x]): G[x].append(y) if undirected: G.make_undirected() return G
Example #14
Source File: graph_builder_test.py From HumanRecognition with MIT License | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))
Example #15
Source File: graph.py From deepwalk with GNU General Public License v3.0 | 5 votes |
def make_undirected(self): t0 = time() for v in list(self): for other in self[v]: if v != other: self[other].append(v) t1 = time() logger.info('make_directed: added missing edges {}s'.format(t1-t0)) self.make_consistent() return self
Example #16
Source File: graph_builder_test.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))
Example #17
Source File: graph_builder_test.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))
Example #18
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 5 votes |
def speciesData(): program_type,database_dir = unique.whatProgramIsThis() filename = 'Config/species.txt' fn=filepath(filename); global species_list; species_list=[]; global species_codes; species_codes={} for line in open(fn,'r').readlines(): data = cleanUpLine(line) abrev,species = string.split(data,'\t') species_list.append(species) species_codes[species] = abrev
Example #19
Source File: graph_builder_test.py From object_detection_with_tensorflow with MIT License | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))
Example #20
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def normalize_input(self): input = [] for line in self.input.decode().split('\n'): line = line.strip() line2 = line.encode('unicode_escape') input.append(line2) self.input = b'\n'.join(input)
Example #21
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 5 votes |
def pathToString(path_list): path_str=[] for path_int in path_list: path_str.append(str(path_int)) path_index = string.join(path_str,'.') return path_index
Example #22
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 5 votes |
def getDirectoryFiles(import_dir, search_term): matching_files = [] dir_list = read_directory(import_dir) #send a sub_directory to a function to identify all files in a directory for data in dir_list: #loop through each file in the directory to output results affy_data_dir = import_dir[1:]+'/'+data if search_term in affy_data_dir: matching_files.append(affy_data_dir) return matching_files ################# Import and Annotate Data
Example #23
Source File: OBO_import.py From altanalyze with Apache License 2.0 | 5 votes |
def read_directory(sub_dir): dir_list = unique.read_directory(sub_dir); dir_list2 = [] ###Code to prevent folder names from being included for entry in dir_list: if entry[-4:] == ".txt" or entry[-4:] == ".csv" or ".ontology" in entry or '.obo' in entry: dir_list2.append(entry) return dir_list2 ###### Classes ######
Example #24
Source File: graph_builder_test.py From object_detection_kitti with Apache License 2.0 | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))
Example #25
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def extract_bytes(line): linet = line.split(' | ') strbytes = [linet[1][i:i+2] for i in range(0, len(linet[1]), 3)] bytes = [] for s in strbytes: bytes.append(s) return bytes
Example #26
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def construct_comparator_dump(self, mapping): def toprint(x, src): c = x if len(c) == 0: c = ' ' elif len(c) == 2: c = x[1] if ord(c) >= 0x20 and ord(c) < 0x7f: return c else: return '.' for i, chunk in enumerate(HexDumpPrinter.extract_chunks(mapping)): chunk = list(chunk) # save generator result in a list src, mapped = zip(*chunk) values = [] for left, right in zip(src, mapped): if left == right: values.append('') # byte matches original elif len(right) == 0: values.append('-1') # byte dropped elif len(right) == 2: values.append('+1') # byte expanded else: values.append(bin2hex(right)) # byte modified line1 = '%04x' % (i * 16) + ' | ' + bin2hex(src).ljust(49, ' ') line2 = '%04x' % (i * 16) + ' | ' + ' '.join(sym.ljust(2, self.fill_matching) for sym in values) line1 += '| ' + ''.join(map(lambda x: x if ord(x) >= 0x20 and ord(x) < 0x7f else '.', src)).ljust(16, ' ') ascii2 = '| ' for i in range(len(values)): ascii2 += toprint(values[i], src[i]) for i in range(len(values), 16): ascii2 += ' ' line2 = line2.ljust(56, ' ') line2 += ascii2 #out(dbg("Line1: ('%s')" % line1)) #out(dbg("Line2: ('%s')" % line2)) self.dump1.append(line1) self.dump2.append(line2)
Example #27
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def get_grid(self): ''' Builds a 2-d suffix grid for our DP algorithm. ''' x = self.x y = self.y[:len(x)*2] width, height = len(x), len(y) values = [[0] * (width + 1) for j in range(height + 1)] moves = [[0] * (width + 1) for j in range(height + 1)] equal = [[x[i] == y[j] for i in range(width)] for j in range(height)] equal.append([False] * width) for j, i in itertools.product(rrange(height + 1), rrange(width + 1)): value = values[j][i] if i >= 1 and j >= 1: if equal[j-1][i-1]: values[j-1][i-1] = value + 1 moves[j-1][i-1] = 2 elif value > values[j][i-1]: values[j-1][i-1] = value moves[j-1][i-1] = 2 if i >= 1 and not equal[j][i-1] and value - 2 > values[j][i-1]: values[j][i-1] = value - 2 moves[j][i-1] = 1 if i >= 1 and j >= 2 and not equal[j-2][i-1] and value - 1 > values[j-2][i-1]: values[j-2][i-1] = value - 1 moves[j-2][i-1] = 3 return (values, moves)
Example #28
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def draw_chunk_table(comp): ''' Outputs a table that compares the found memory chunks side-by-side in input file vs. memory ''' table = [('', '', '', '', 'File', 'Memory', 'Note')] delims = (' ', ' ', ' ', ' | ', ' | ', ' | ', '') last_unmodified = comp.get_last_unmodified_chunk() for c in comp.get_chunks(): if c.dy == 0: note = 'missing' elif c.dx > c.dy: note = 'compacted' elif c.dx < c.dy: note = 'expanded' elif c.unmodified: note = 'unmodified!' else: note = 'corrupted' table.append((c.i, c.j, c.dx, c.dy, shorten_bytes(c.xchunk), shorten_bytes(c.ychunk), note)) # draw the table sizes = tuple(max(len(str(c)) for c in col) for col in zip(*table)) for i, row in enumerate(table): out('\t' + ''.join(str(x).ljust(size) + delim for x, size, delim in zip(row, sizes, delims))) if i == 0 or (i == last_unmodified + 1 and i < len(table)): out('\t' + '-' * (sum(sizes) + sum(len(d) for d in delims))) # # Memory comparison algorithm originally taken from Mona.py by Peter Van Eeckhoutte - Corelan GCV # https://github.com/corelan/mona # # It utilizes modified Longest Common Subsequence algorithm to mark number of modifications over # supplied input to let it be transformed into another input, as compared to. #
Example #29
Source File: badchars.py From expdevBadChars with GNU General Public License v3.0 | 5 votes |
def post_process_bytes_line(line): outb = [] l = line.strip()[:] strip = ['0x', ',', ' ', '\\', 'x', '%u', '+', '.', "'", '"'] for s in strip: l = l.replace(s, '') for i in range(0, len(l), 2): outb.append(int(l[i:i+2], 16)) return outb
Example #30
Source File: graph_builder_test.py From hands-detection with MIT License | 5 votes |
def _find_input_path(src, dst_predicate): """Finds an input path from `src` to a node that satisfies `dst_predicate`. TensorFlow graphs are directed. We generate paths from outputs to inputs, recursively searching both direct (i.e. data) and control inputs. Graphs with while_loop control flow may contain cycles. Therefore we eliminate loops during the DFS. Args: src: tf.Tensor or tf.Operation root node. dst_predicate: function taking one argument (a node), returning true iff a a target node has been found. Returns: a path from `src` to the first node that satisfies dest_predicate, or the empty list otherwise. """ path_to = {src: None} def dfs(x): if dst_predicate(x): return x x_op = _as_op(x) for y in x_op.control_inputs + list(x_op.inputs): # Check if we've already visited node `y`. if y not in path_to: path_to[y] = x res = dfs(y) if res is not None: return res return None dst = dfs(src) path = [] while dst in path_to: path.append(dst) dst = path_to[dst] return list(reversed(path))