2 # Copyright (c) 2016 Samsung Electronics Co., Ltd
4 # Licensed under the Flora License, Version 1.1 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://floralicense.org/license/
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 from tic.utils.file import make_dirs, decompress_gzip, copyfile_flock
22 from tic.utils.grabber import myurlgrab2
25 class MyThread(threading.Thread):
26 def __init__(self, name, url):
27 threading.Thread.__init__(self)
30 self.__suspend = False
32 self.__path = './test/thread/'
33 self.__cachepath = './test/thread/cache'
35 print('%s Thread start !!!' % self.name)
36 path=os.path.join(self.__path, self.name)
38 filename=os.path.join(path, os.path.basename(self.url))
39 myurlgrab2(self.url, filename)
40 print('%s Thread download file !!!' % self.name)
41 # Check if file compressed or not
42 if filename.endswith(".gz"):
43 decompress_filename = os.path.splitext(filename)[0]
44 filename = decompress_gzip(filename, decompress_filename)
45 print('%s Thread decompress file !!!' % self.name)
47 cachefile = os.path.join(self.__cachepath, os.path.basename(filename))
48 copyfile_flock(filename, cachefile)
49 print('%s Thread finish !!!' % self.name)
54 self.__suspend = False
58 if __name__ == '__main__':
60 th1 = MyThread('th1', url)
62 # th2 = MyThread('th2', url)