Skip to content

Commit d4f38e8

Browse files
committed
First version on Pypi
1 parent 80ceb58 commit d4f38e8

File tree

6 files changed

+23
-36
lines changed

6 files changed

+23
-36
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# orpa-pylib
2-
library for easily creating rpas in python
1+
# ofilepy-pylib
2+
A library to make easier work with files in local system

dist/ofilepy-1.1.1.tar.gz

-4.14 KB
Binary file not shown.

dist/ofilepy-1.1.2.tar.gz

4 KB
Binary file not shown.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='ofilepy',
8-
version='1.1.1',
8+
version='1.1.2',
99
license='MIT License',
1010
author='Lincoln Oliver',
1111
long_description=readme,

src/ofilepy.egg-info/PKG-INFO

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 2.1
22
Name: ofilepy
3-
Version: 1.1.1
3+
Version: 1.1.2
44
Summary: A library to make easier work with files in local system
55
Home-page: https://github.com/lincolnolivr/pylib_ofilepy.git
66
Author: Lincoln Oliver
@@ -10,5 +10,5 @@ Keywords: files manipulation with python
1010
Description-Content-Type: text/markdown
1111
License-File: LICENSE
1212

13-
# orpa-pylib
14-
library for easily creating rpas in python
13+
# ofilepy-pylib
14+
A library to make easier work with files in local system

src/ofilepy/ofilepy.py

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# %%
2-
__version__ = '1.1.0'
2+
__version__ = '1.1.2'
33

44
# %% [markdown]
55
# # ofilepath Lib (Moving/Copying/Getting Files Information)
@@ -36,7 +36,7 @@ def get_last_file(file_path: str=None, extension: bool=True, file_type: str='',
3636

3737
return file
3838

39-
def get_last_file_name(file_path=None,extension=True,file_type='',contains=''):
39+
def get_last_file_name(file_path: str=None, extension: bool=True, file_type: str='', contains: str=''):
4040
if file_path == None: file_path = get_downloads_folder()
4141
try:
4242
list_of_files = [str(file) for file in pathlib.Path(file_path).iterdir() if not file.is_dir() and str(file).endswith(file_type) and contains in str(file)]
@@ -55,7 +55,7 @@ def get_last_file_name(file_path=None,extension=True,file_type='',contains=''):
5555
except:
5656
return print('Any file was found!')
5757

58-
def move_the_last_file(old_path,new_path,file_type='',contains='',delete=False):
58+
def move_the_last_file(old_path:str , new_path:str , file_type:str ='', contains: str='', delete: bool=False):
5959
list_of_files = [str(i) for i in pathlib.Path(old_path).iterdir() if not i.is_dir() and str(i).endswith(file_type) and contains in str(i)]
6060
latest_file = max(list_of_files, key=os.path.getctime)
6161
new_file = latest_file.replace(old_path,new_path)
@@ -73,33 +73,33 @@ def move_the_last_file(old_path,new_path,file_type='',contains='',delete=False):
7373
os.remove(new_file)
7474
os.rename(latest_file, new_file)
7575

76-
def rename_file(old_path,new_path,delete=False):
76+
def rename_file(old_path: str, new_path:str , delete:bool=False):
7777
if delete == False:
7878
try: os.rename(old_path, new_path)
7979
except: print('File already exist!')
8080
else:
8181
try: os.rename(old_path, new_path)
8282
except: os.remove(new_path); os.rename(old_path, new_path)
8383

84-
def copy_the_last_file(old_path,new_path,file_type=''):
84+
def copy_the_last_file(old_path:str, new_path:str, file_type:str=''):
8585
list_of_files = [str(i) for i in pathlib.Path(old_path).iterdir() if not i.is_dir() and file_type in str(i)]
8686
lastest_file = max(list_of_files, key=os.path.getctime)
8787
lastest_file_name = lastest_file[(len(lastest_file) - lastest_file[::-1].find('\\')):]
8888
new_file_name = lastest_file[(len(lastest_file) - lastest_file[::-1].find('\\')):]
8989
new_file = lastest_file.replace(old_path,new_path).replace(lastest_file_name,new_file_name)
9090
shutil.copy(lastest_file,new_file)
9191

92-
def get_subfolders(folder_path):
92+
def get_subfolders(folder_path: str):
9393
subfolder = [str(i) for i in pathlib.Path(folder_path).iterdir() if i.is_dir()]
9494

9595
return subfolder
9696

97-
def get_files(folder_path, file_type='',contains=''):
97+
def get_files(folder_path:str, file_type: str='', contains:str=''):
9898
files = [str(i) for i in pathlib.Path(folder_path).iterdir() if not i.is_dir() and file_type in str(i) and contains in str(i)]
9999

100100
return files
101101

102-
def get_all_files(folder_path,file_type='',contains='',include_path=True):
102+
def get_all_files(folder_path: str, file_type: str='', contains:str='', include_path:bool=True):
103103
filelist = []
104104

105105
for root, dir, files in os.walk(folder_path):
@@ -108,30 +108,29 @@ def get_all_files(folder_path,file_type='',contains='',include_path=True):
108108
filelist.append(os.path.join(root,file))
109109

110110
elif str(file).endswith(file_type) and contains in str(file):
111-
filelist.append(file)
112-
111+
filelist.append(file)
113112
return filelist
114113

115-
def is_file_open(file_path):
114+
def is_file_open(file_path: str):
116115
try:
117116
with open(file_path, 'r+') as f:
118117
print('file is closed, proceed to write')
119118
except PermissionError:
120119
print('file is open, close it and try again')
121120

122-
def get_downloads_folder(downloads_folder_name='Downloads'):
121+
def get_downloads_folder(downloads_folder_name: str='Downloads'):
123122
downloads_folder = os.path.join(os.path.expanduser('~'), downloads_folder_name)
124123
return downloads_folder
125124

126-
def detect_file_download(download_path=None,tries=50,wait=1):
125+
def detect_file_download(download_path: str=None, tries: int=50, wait:float=1):
127126
if download_path is None: download_path = get_downloads_folder()
128127
tries_count = 0
129128
while True and tries_count <= tries:
130129
time.sleep(wait)
131130
if len(get_files(download_path)) > 0: break
132131
else: tries_count += 1
133132

134-
def detect_file_download_with_criteria(folder_path: str=None,file_type='',contains='',tries=50, wait=5):
133+
def detect_file_download_with_criteria(folder_path: str=None, file_type: str='', contains: str='', tries: int=50, wait: float=5):
135134
if folder_path is None: folder_path = get_downloads_folder()
136135

137136
def is_file_downloaded():
@@ -147,7 +146,7 @@ def is_file_downloaded():
147146
print('File was not downloaded!')
148147
return False
149148

150-
def adding_prefix_to_files(file_path: str=None, file_type: str='', contains: str='',prefix: str=''):
149+
def adding_prefix_to_files(file_path: str=None, file_type: str='', contains: str='', prefix: str=''):
151150
if file_path is None: file_path = get_downloads_folder()
152151

153152
list_of_files = [str(i) for i in pathlib.Path(file_path).iterdir() if not i.is_dir() and i.endswith(file_type) and contains in str(i)]
@@ -158,7 +157,7 @@ def adding_prefix_to_files(file_path: str=None, file_type: str='', contains: str
158157
os.rename(file,file_new)
159158
print('Done!')
160159

161-
def remove_files_by_date(folder_path: str, cutoff_date, comparison, include_subs: bool=False):
160+
def remove_files_by_date(folder_path: str, cutoff_date: datetime.datetime, comparison: str, include_subs: bool=False):
162161
for root, directories, files in os.walk(folder_path):
163162
if not include_subs:
164163
directories.clear()
@@ -190,7 +189,7 @@ def get_access_date(file_path: str):
190189
access_date = datetime.datetime.fromtimestamp(timestamp)
191190
return access_date
192191

193-
def get_file_size(file_path: str,size: str='default'):
192+
def get_file_size(file_path: str, size: str='default'):
194193
if size == 'default': file_size = os.path.getsize(file_path)
195194
elif size == 'kb': file_size = os.path.getsize(file_path) / 1024
196195
elif size == 'mb': file_size = os.path.getsize(file_path) / (1024 * 1024)
@@ -226,16 +225,4 @@ def check_file_type(file: str, file_types: tuple[str]):
226225
"""
227226
Check if the file is of a certain type.
228227
"""
229-
return file.lower().endswith(file_types)
230-
231-
def get_local_sharepoint_path(sharepoint_site, raw_adress):
232-
sharepoint_local_folder = os.path.expanduser('~/MFP Michelin')
233-
if raw_adress.startswith('/'):
234-
raw_adress = raw_adress[1:]
235-
for folder in os.listdir(sharepoint_local_folder):
236-
site = folder.split(' - ')[0]
237-
if sharepoint_site == site or sharepoint_site == folder:
238-
sharepoint_site_folder = folder
239-
break
240-
return os.path.join(sharepoint_local_folder, sharepoint_site_folder, raw_adress)
241-
228+
return file.lower().endswith(file_types)

0 commit comments

Comments
 (0)