Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: TSQL, Created At: 10/24/2016 8:07:26 PMViews:

HTML view:
Copy Source | Copy HTML
  1. #-*- encoding: utf-8
  2. import networkx as nx
  3. import matplotlib.pyplot as plt
  4. import os
  5. def get_tree(tree=[u"E:\\Музыка",], G=nx.Graph(), itr=0, max_itr=900):
  6.     point = tree.pop(0)
  7.     itr = itr + 1
  8.     sub_tree = [os.path.join(point, x) for x in os.listdir(point) if os.path.isdir(os.path.join(point, x)) and not is_hidden_dir(os.path.join(point, x))]
  9.     if sub_tree:
  10.         tree.extend(sub_tree)
  11.         G.add_edges_from(map(lambda b : (point, b), sub_tree))
  12.     if tree and itr <= max_itr:
  13.         return get_tree(tree, G, itr)
  14.     else:
  15.         return G
  16. def is_hidden_dir(d):
  17.     import sys, subprocess
  18.     if sys.platform.startswith("win"):
  19.         p = subprocess.check_output(["attrib", d.encode('cp1251') if isinstance(d, unicode) else d])
  20.         return True if 'H' in p[:12] else False
  21.     else:
  22.         return True if os.path.basename(d)[0] == '.' else False
  23. def main():
  24.     G = get_tree()
  25.     nx.draw(G, with_labels=False, node_color="blue", alpha=0.6, node_size=50)
  26.     plt.savefig("edge_colormap.png")
  27.     plt.show()
  28. if __name__ == "__main__":
  29.     main()

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017