1 '''
2 Created on Aug 11, 2010
3
4 @author: dwmclary
5 '''
6 import networkx as nx
7 from .. hdmc import hdfs
9 '''
10 Provides graph handles in Hadoop MapReduce
11 '''
12
13
14 - def __init__(self, G = None, graph_handle=None):
15 '''
16 Constructor
17 '''
18
19 if G != None:
20 self.G = G
21
22 if graph_handle != None:
23 self.graph_handle = graph_handle
24
27
29 if undirected:
30 self.G = nx.read_adjlist(filename).to_undirected()
31 else:
32 self.G = nx.read_adjlist(filename)
33 self.graph_handle = filename
34
36 if filename:
37 nx.write_adjlist(self.G.to_directed(), filename)
38 self.graph_handle = filename
39 hdfs.copyToHDFS(filename, filename)
40 else:
41 if self.graph_handle:
42 nx.write_adjlist(self.G.to_directed(), self.graph_handle)
43
46
48 listing = hdfs.ls(self.graph_handle)["stdout"].split("\n")
49 found = False
50 disk_tail = self.graph_handle.split("/")[-1]
51 for line in listing:
52 hdfs_tail = line.split("/")[-1]
53 if disk_tail == hdfs_tail:
54 found = True
55 break
56 return found
57