bp_utils.py
Go to the documentation of this file.
1 import os
2 import sys
3 
4 import bp_config as config #/// User Configuration
5 
6 def progressBar(value, endvalue, docdb_id, bar_length=40):
7  percent = float(value) / endvalue
8  arrow = '=' * int(round(percent * bar_length)-1) + '>'
9  spaces = ' ' * (bar_length - len(arrow))
10 
11  sys.stdout.write("\rProgress: [\033[01;32m{0}\033[00m] {1}/{2} ({3}%) -- DocDB {4}".format(arrow + spaces, value, endvalue, int(round(percent * 100)), docdb_id))
12  sys.stdout.flush()
13 
14 
16  ret = []
17  for root, dirs, files in os.walk(dir):
18  # ignore weird system directories
19  if root.find('__MACOSX') > 0: continue
20 
21  # loop over files in dir and all subdirectories
22  for file in files:
23  # ignore dotfilfes
24  if file.startswith('.'): continue
25 
26  # ignore files that don't have an expected .txt extension
27  if os.path.splitext(os.path.basename(file))[1][1:] not in config.CAPTION_EXTS: continue
28  ret.append('{}/{}'.format(root, file)[2:])
29 
30  # find all files with images extensions that are associated with this caption file
31  for file2 in files:
32  if os.path.splitext(os.path.basename(file2))[0] != os.path.splitext(os.path.basename(file))[0] or os.path.splitext(os.path.basename(file2))[1][1:] not in config.PLOT_EXTS: continue
33 
34  ret.append('{}/{}'.format(root, file2)[2:])
35 
36  return ret
37 
38 
40  ret = []
41  for root, dirs, files in os.walk(dir):
42  # ignore weird system directories
43  if root.find('__MACOSX') > 0: continue
44 
45  # loop over files in dir and all subdirectories
46  for file in files:
47  # ignore dotfilfes
48  if file.startswith('.'): continue
49 
50  # ignore files that don't have an expected .txt extension
51  if os.path.splitext(os.path.basename(file))[1][1:] not in config.CAPTION_EXTS: continue
52  ret.append('{}/{}'.format(root, file)[2:])
53 
54  return ret
55 
56 
58  ret = []
59  for root, dirs, files in os.walk(dir):
60  # ignore weird system directories
61  if root.find('__MACOSX') > 0: continue
62 
63  # loop over files in dir and all subdirectories
64  for file in files:
65  # ignore dotfilfes
66  if file.startswith('.'): continue
67 
68  if os.path.splitext(os.path.basename(file))[0] != os.path.splitext(os.path.basename(cap))[0] or os.path.splitext(os.path.basename(file))[1][1:] not in config.PLOT_EXTS: continue
69 
70  ret.append('{}/{}'.format(root, file)[2:])
71 
72  return ret
def progressBar(value, endvalue, docdb_id, bar_length=40)
Definition: bp_utils.py:6
fvar< T > round(const fvar< T > &x)
Definition: round.hpp:23
def ListPlotsInDirForCaption(dir, cap)
Definition: bp_utils.py:57
def ListCaptionFilesInDir(dir)
Definition: bp_utils.py:39
std::string format(const int32_t &value, const int &ndigits=8)
Definition: HexUtils.cpp:14
def ListBlessedFilesInDir(dir)
Definition: bp_utils.py:15