-
Notifications
You must be signed in to change notification settings - Fork 1
/
filesline.py
62 lines (58 loc) · 2.14 KB
/
filesline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
# .---. .-----------
# / \ __ / ------
# / / \( )/ ----- (`-') _ _(`-') <-. (`-')_
# ////// '\/ ` --- ( OO).-/( (OO ).-> .-> \( OO) ) .->
# //// / // : : --- (,------. \ .'_ (`-')----. ,--./ ,--/ ,--.' ,-.
# // / / / `\/ '-- | .---' '`'-..__)( OO).-. ' | \ | | (`-')'.' /
# // //..\\ (| '--. | | ' |( _) | | | | . '| |)(OO \ /
# ============UU====UU==== | .--' | | / : \| |)| | | |\ | | / /)
# '//||\\` | `---. | '-' / ' '-' ' | | \ | `-/ /`
# ''`` `------' `------' `-----' `--' `--' `--'
# ######################################################################################
#
# Author: edony - edonyzpc@gmail.com
#
# twitter : @edonyzpc
#
# Last modified: 2017-09-15 15:33
#
# Filename: filesline.py
#
# Description: All Rights Are Reserved
#
"""
import sys
import os
from dirlist import DirList
class FilesLine(DirList):
"""generate the line number of files located in directory
"""
def __init__(self, directory):
super(FilesLine, self).__init__(directory)
self.filesline = 0
def sum_lines(self):
# TODO(edony): optimize algorithm of sum_lines method
filesname = []
for item_dir in self.dirlist.keys():
for item_file in self.dirlist[item_dir][1]:
filesname.append(item_dir + '/' + item_file)
for filename in filesname:
with open(filename, 'rb') as filebuf:
self.filesline += len(filebuf.readlines())
return self.filesline
""" comment this line to test with __main__
if __name__ == "__main__":
import time
tmp = DirList('/Users/edony/coding/toolkitem')
#print(tmp.dirlist)
#print(sys.path)
#print(os.path.split(os.path.realpath(__file__)))
tmp1 = FilesLine('/Users/edony/coding/toolkitem')
print(tmp1.dirlist)
print(time.time())
tmp1.sum_lines()
print(time.time())
comment this line to test with __main__ """