-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_Python_utilities.py
More file actions
112 lines (94 loc) · 3.73 KB
/
_Python_utilities.py
File metadata and controls
112 lines (94 loc) · 3.73 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""
Created on Thu Nov 22 01:00:19 2018
@author: guitar79@naver.com
ModuleNotFoundError: No module named 'ccdproc'
conda install -c condaforge ccdproc
"""
from datetime import datetime
# =============================================================================
# creat log
# =============================================================================
def write_log(log_file, log_str):
import time
timestamp = time.strftime('%Y-%m-%d %H:%M:%S')
msg = '[' + timestamp + '] ' + log_str
print(msg)
with open(log_file, 'a') as f:
f.write(msg + '\n')
def write_log2(log_file, log_str):
import os
with open(log_file, 'a') as log_f:
log_f.write("{}, {}\n".format(os.path.basename(__file__), log_str))
return print ("{}, {}\n".format(os.path.basename(__file__), log_str))
# =============================================================================
# for checking time
# =============================================================================
cht_start_time = datetime.now()
def print_working_time(cht_start_time):
working_time = (datetime.now() - cht_start_time) #total days for downloading
return print('working time ::: %s' % (working_time))
master_file_dir_name = 'master_file_Python/'
processing_dir_name = 'processing_Python/'
integration_dir_name = 'integration_Python/'
alignment_dir_name = 'alignment_Python/'
# =============================================================================
# getFullnameListOfallFiles
# =============================================================================
def create_connection(db_file):
import sqlite3
from sqlite3 import Error
""" create a database connection to the SQLite database
specified by the db_file
:param db_file: database file
:return: Connection object or None
"""
try:
conn = sqlite3.connect(db_file, timeout=10)
return conn
except Error as e:
print(e)
return None
# =============================================================================
# getFullnameListOfallFiles
# =============================================================================
def getFullnameListOfallFiles(dirName):
##############################################3
import os
# create a list of file and sub directories
# names in the given directory
listOfFile = sorted(os.listdir(dirName))
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getFullnameListOfallFiles(fullPath)
else:
allFiles.append(fullPath)
return allFiles
# =============================================================================
# getFullnameListOfallFiles
# =============================================================================
def getFullnameListOfsubDirs(dirName):
##############################################3
import os
allFiles = list()
for file in sorted(os.listdir(dirName)):
d = os.path.join(dirName, file)
if os.path.isdir(d):
allFiles.append(d)
return allFiles
# =============================================================================
# getFullnameListOfallsubDirs
# =============================================================================
def getFullnameListOfallsubDirs(dirName):
##############################################3
import os
allFiles = list()
for it in os.scandir(dirName):
if it.is_dir():
allFiles.append(it.path)
allFiles.extend(getFullnameListOfallsubDirs(it))
return allFiles