comparison TrackHub.py @ 16:3233451a3bd6 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit fc73ec22a0db3ab09c4ac13dc58f0b54ae37845c
author rmarenco
date Sun, 25 Sep 2016 11:25:38 -0400
parents d05236b15f81
children c02720d1afee
comparison
equal deleted inserted replaced
15:2a45cd656e8e 16:3233451a3bd6
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf8 -*- 2 # -*- coding: utf8 -*-
3 3
4 import logging
4 import os 5 import os
5 import tempfile 6 import tempfile
6 import shutil 7 import shutil
7 import zipfile 8 import zipfile
8 9
86 mytemplate = mylookup.get_template('display.txt') 87 mytemplate = mylookup.get_template('display.txt')
87 with open(self.outputFile, 'w') as htmlOutput: 88 with open(self.outputFile, 'w') as htmlOutput:
88 # TODO: We are basically looping two times: One time with os.walk, Second time 89 # TODO: We are basically looping two times: One time with os.walk, Second time
89 # with the template. We could improve that if the number of files begins to be really important 90 # with the template. We could improve that if the number of files begins to be really important
90 list_relative_file_path = [ ] 91 list_relative_file_path = [ ]
92
93 # TODO: Create classes Tree to manage this => Better readibility and maintenability
94 def create_tree(array_path, tree, relative_array_file_path, level=0):
95 cur_relative_file_path = '/'.join(relative_array_file_path[:level+1])
96 if array_path[0] in tree.keys():
97 create_tree(array_path[1:], tree[array_path[0]][0],
98 relative_array_file_path, level+1)
99 else:
100 tree[array_path[0]] = ({}, cur_relative_file_path)
101 # TODO: Manage also the links of the directories => No link?
102 # => Managed in display.txt, but could also be managed there
103 # If we are don't have any sub-vertices
104 if len(array_path) == 1:
105 # We create the path to it
106 return
107 else:
108 create_tree(array_path[1:], tree[array_path[0]][0],
109 relative_array_file_path, level + 1)
110
111 walkable_tree = {}
91 for root, dirs, files in os.walk(self.extra_files_path): 112 for root, dirs, files in os.walk(self.extra_files_path):
113 # Prepare the tree from to perform a Depth First Search
92 for file in files: 114 for file in files:
93 relative_directory = os.path.relpath(root, self.extra_files_path) 115 relative_directory = os.path.relpath(root, self.extra_files_path)
94 relative_file_path = os.path.join(relative_directory, file) 116 relative_file_path = os.path.join(relative_directory, file)
95 list_relative_file_path.append(relative_file_path) 117 array_path = relative_file_path.split('/')
96 118 create_tree(array_path, walkable_tree, array_path, 0)
97 htmlMakoRendered = mytemplate.render( 119
98 list_relative_file_path=list_relative_file_path 120 htmlMakoRendered = mytemplate.render(
121 walkable_tree=walkable_tree
99 ) 122 )
100 htmlOutput.write(htmlMakoRendered) 123 htmlOutput.write(htmlMakoRendered)
101 124
102 def __createAssemblyHub__(self, extra_files_path): 125 def __createAssemblyHub__(self, extra_files_path):
103 # Get all necessaries infos first 126 # Get all necessaries infos first