libjam 0.0.9__py3-none-any.whl → 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
libjam/drawer.py CHANGED
@@ -10,14 +10,6 @@ PLATFORM = platform.system()
10
10
 
11
11
  # Internal functions
12
12
  joinpath = os.path.join
13
- def realpath(path: str or list):
14
- if type(path) == str:
15
- return os.path.normpath(path)
16
- elif type(path) == list:
17
- result_list = []
18
- for item in path:
19
- result_list.append(os.path.normpath(item))
20
- return result_list
21
13
 
22
14
  def outpath(path: str or list):
23
15
  if type(path) == str:
@@ -28,12 +20,35 @@ def outpath(path: str or list):
28
20
  result_list.append(item.replace(os.sep, '/'))
29
21
  return result_list
30
22
 
23
+ HOME = str(pathlib.Path.home())
24
+
25
+ def realpath(path: str):
26
+ path_prefixes = ['/', '~']
27
+ first_char = path[0]
28
+ if first_char in path_prefixes:
29
+ path = path.replace('~', HOME)
30
+ return os.path.normpath(path)
31
+ else:
32
+ return path
33
+
34
+ def realpaths(path: list):
35
+ result_list = []
36
+ for item in path:
37
+ result_list.append(realpath(item))
38
+ return result_list
31
39
 
32
40
  # Deals with files
33
41
  class Drawer:
34
42
 
43
+ # Converts the given path to absolute
44
+ def absolute_path(self, path):
45
+ path = realpath(path)
46
+ return outpath(path)
47
+
35
48
  # Returns True if give a path to folder
36
49
  def is_folder(self, path: str):
50
+ if path == '':
51
+ return False
37
52
  path = realpath(path)
38
53
  return os.path.isdir(path)
39
54
 
@@ -147,13 +162,14 @@ class Drawer:
147
162
 
148
163
  # Sends given file(s)/folder(s) to trash
149
164
  def trash(self, path: str or list):
150
- path = realpath(path)
151
165
  if type(path) == str:
166
+ path = realpath(path)
152
167
  try:
153
168
  send2trash.send2trash(path)
154
169
  except FileNotFoundError:
155
170
  print(f"File '{path}' wasn't found, skipping sending it to trash.")
156
171
  elif type(path) == list:
172
+ path = realpaths(path)
157
173
  for item in path:
158
174
  try:
159
175
  send2trash.send2trash(item)
@@ -166,11 +182,12 @@ class Drawer:
166
182
 
167
183
  # Deletes a given file (using trash_file() instead is recommended)
168
184
  def delete_file(self, path: str or list):
169
- path = realpath(path)
170
185
  if type(path) == str:
186
+ path = realpath(path)
171
187
  if self.is_file(path):
172
188
  os.remove(path)
173
189
  elif type(path) == list:
190
+ path = realpaths(path)
174
191
  for item in path:
175
192
  if self.is_file(path):
176
193
  os.remove(item)
@@ -195,13 +212,14 @@ class Drawer:
195
212
 
196
213
  # Returns the parent folder of given file/folder
197
214
  def get_parent(self, path: str or list):
198
- path = realpath(path)
199
215
  if type(path) == str:
216
+ path = realpath(path)
200
217
  basename = self.basename(path)
201
218
  parent = path.removesuffix(basename)
202
219
  parent = parent.removesuffix(os.sep)
203
220
  return outpath(parent)
204
221
  elif type(path) == list:
222
+ path = realpaths(path)
205
223
  result_list = []
206
224
  for file in path:
207
225
  basename = self.basename(file)
@@ -218,14 +236,15 @@ class Drawer:
218
236
  return depth
219
237
 
220
238
  def basename(self, path: str or list):
221
- path = realpath(path)
222
239
  if type(path) == str:
240
+ path = realpath(path)
223
241
  if self.is_folder(path):
224
242
  path = os.path.basename(os.path.normpath(path))
225
243
  else:
226
244
  path = path.rsplit(os.sep,1)[-1]
227
245
  return outpath(path)
228
246
  elif type(path) == list:
247
+ path = realpaths(path)
229
248
  return_list = []
230
249
  for file in path:
231
250
  if self.is_file(file):
@@ -237,7 +256,7 @@ class Drawer:
237
256
 
238
257
  # Searches for string in list of basenames
239
258
  def search_for_files(self, search_term: str, path: list):
240
- path = realpath(path)
259
+ path = realpaths(path)
241
260
  result_list = []
242
261
  files = self.get_files_recursive(path)
243
262
  for file in files:
@@ -247,15 +266,16 @@ class Drawer:
247
266
  return outpath(result_list)
248
267
 
249
268
  def search_for_folder(self, search_term: str, path: str or list):
250
- path = realpath(path)
251
269
  result_list = []
252
270
  if type(path) == str:
271
+ path = realpath(path)
253
272
  subfolders = self.get_folders(path)
254
273
  for item in subfolders:
255
274
  basename = self.basename(item)
256
275
  if basename == search_term:
257
276
  result_list.append(item)
258
277
  elif type(path) == list:
278
+ path = realpaths(path)
259
279
  for subfolder in path:
260
280
  subfolders = self.get_folders(subfolder)
261
281
  for item in subfolders:
@@ -265,7 +285,6 @@ class Drawer:
265
285
  return outpath(result_list)
266
286
 
267
287
  def search_for_folders(self, search_term: str, path: str or list):
268
- path = realpath(path)
269
288
  result_list = []
270
289
  def search(search_term: str, path: str):
271
290
  folders = self.get_folders_recursive(path)
@@ -274,8 +293,10 @@ class Drawer:
274
293
  if search_term.lower() in basename.lower():
275
294
  result_list.append(folder)
276
295
  if type(path) == str:
296
+ path = realpath(path)
277
297
  search(search_term, path)
278
298
  elif type(path) == list:
299
+ path = realpaths(path)
279
300
  for subfolder in path:
280
301
  search(search_term, subfolder)
281
302
  return outpath(result_list)
@@ -302,6 +323,8 @@ class Drawer:
302
323
  return False
303
324
 
304
325
  # Extracts a given archive
326
+ # progress_function is called every time a file is extracted from archive, and
327
+ # it passes number of extracted files and number of files that need to be extracted (done, total)
305
328
  def extract_archive(self, archive: str, extract_location: str, progress_function=None):
306
329
  archive = realpath(archive)
307
330
  extract_location = realpath(extract_location)
@@ -338,8 +361,7 @@ class Drawer:
338
361
 
339
362
  # Returns the home folder
340
363
  def get_home(self):
341
- home = str(pathlib.Path.home())
342
- return outpath(home)
364
+ return outpath(HOME)
343
365
 
344
366
  # Returns the temporary folder
345
367
  def get_temp(self):
@@ -361,17 +383,17 @@ class Drawer:
361
383
  typewriter.print('Program aborted while gathering size of files.')
362
384
  sys.exit(1)
363
385
 
364
- def open_path(self, path: str):
386
+ def open(self, path: str):
365
387
  path = realpath(path)
366
388
  if PLATFORM == 'Linux':
367
- subprocess.run(['xdg-open', path])
389
+ command = 'xdg-open'
368
390
  elif PLATFORM == 'Windows':
369
- subprocess.run(['start', path])
391
+ command = 'start'
370
392
  elif PLATFORM == 'Darwin':
371
- subprocess.run(['open', path])
393
+ command = 'open'
372
394
  else:
373
395
  return 1
374
- return 0
396
+ return subprocess.run([command, path])
375
397
 
376
398
  def get_platform(self):
377
399
  return PLATFORM
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libjam
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: A library jam for Python.
5
5
  Project-URL: Homepage, https://github.com/philippkosarev/libjam
6
6
  Project-URL: Issues, https://github.com/philippkosarev/libjam/issues
@@ -1,11 +1,11 @@
1
1
  libjam/__init__.py,sha256=iLE2y9r0Sfe3oIeoFHKwFIyLL6d_KcLP7fINd7pPAlY,145
2
2
  libjam/captain.py,sha256=igx-ecKJBI_vBN-pW7KmSEnmYMIHQEb9tFzpy5qHmI8,5636
3
3
  libjam/clipboard.py,sha256=5HxlO8ztLJPlnSCq4PncGvY4JGc9C4J2uHcepjC6zmg,3496
4
- libjam/drawer.py,sha256=gy887B5heBbzqT0R_36U3vaGiiR4avsZ4b52Uabhz2I,11491
4
+ libjam/drawer.py,sha256=vKL1iN8chHjXZRsTdmhE8qpDaZAgh7Orx5KtrvgplcE,12100
5
5
  libjam/flashcard.py,sha256=ulV4KPC3BRWLxwkQ87vsY0aM38nYpzOjUOISxTIRVDg,437
6
6
  libjam/notebook.py,sha256=4aLVRVTefiHMip44TERLJAXv88U8G6mYLqc1UvWsEfs,3108
7
7
  libjam/typewriter.py,sha256=waKY1sDxGzI2ZT5dSzFmLGbaNTIpEM5Zhg_OlPFUAng,3730
8
- libjam-0.0.9.dist-info/METADATA,sha256=PDUnOoV4F7RduZA4OJYTL95W-E7tx4eBqWcFJCGE7mo,2140
9
- libjam-0.0.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- libjam-0.0.9.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
11
- libjam-0.0.9.dist-info/RECORD,,
8
+ libjam-0.0.11.dist-info/METADATA,sha256=Mhp9Dd0awHIauzbI3jl0udb3mxNAxrHtB49I1VeD6hM,2141
9
+ libjam-0.0.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ libjam-0.0.11.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
11
+ libjam-0.0.11.dist-info/RECORD,,