text
stringlengths 0
828
|
---|
:param name: path Name: to edit
|
:param blank: default blanks in name
|
:return: Prettier name from given one: replace bad chars with good ones
|
""""""
|
if name.startswith("".""): # remove starting
|
name = name[1:]
|
for bad_char in BAD_CHARS:
|
name = name.replace(bad_char, blank) # remove token
|
name = String(name).remove_all(blank)
|
for i in range(1, len(name) - 2):
|
try:
|
are_blanks = name[i - 1] == blank and name[i + 1] == blank
|
if are_blanks and name[i] in BAD_CHARS:
|
name = name[:i - 1] + name[i + 2:]
|
except: # out of bounds
|
pass
|
if name.startswith(blank):
|
name = name[1:]
|
if name.endswith(blank): # remove ending replacement
|
name = name[:-1]
|
return name"
|
10,"def get_parent_folder_name(file_path):
|
""""""Finds parent folder of file
|
:param file_path: path
|
:return: Name of folder container
|
""""""
|
return os.path.split(os.path.split(os.path.abspath(file_path))[0])[-1]"
|
11,"def ls_dir(path, include_hidden=False):
|
""""""Finds content of folder
|
:param path: directory to get list of files and folders
|
:param include_hidden: True iff include hidden files in list
|
:return: List of paths in given directory
|
""""""
|
lst = []
|
for file in os.listdir(path):
|
hidden_file = FileSystem(file).is_hidden()
|
if (hidden_file and include_hidden) or (not hidden_file):
|
lst.append(os.path.join(path, file))
|
return list(set(lst))"
|
12,"def ls_recurse(path, include_hidden=False):
|
""""""Finds content of folder recursively
|
:param path: directory to get list of files and folders
|
:param include_hidden: True iff include hidden files in list
|
:return: List of paths in given directory recursively
|
""""""
|
lst = []
|
for file in os.listdir(path):
|
hidden_file = FileSystem(file).is_hidden()
|
if (hidden_file and include_hidden) or (not hidden_file):
|
lst.append(os.path.join(path, file))
|
if is_folder(os.path.join(path, file)):
|
lst += ls_recurse(
|
os.path.join(path, file),
|
include_hidden=include_hidden
|
) # get list of files in directory
|
return list(set(lst))"
|
13,"def list_content(path, recurse, include_hidden=False):
|
""""""Finds content of folder (recursively)
|
:param path: directory to get list of files and folders
|
:param recurse: True iff recurse into subdirectories or not
|
:param include_hidden: True iff include hidden files in list
|
:return: List of paths in given directory recursively
|
""""""
|
if recurse:
|
return ls_recurse(path, include_hidden=include_hidden)
|
return ls_dir(path, include_hidden=include_hidden)"
|
14,"def is_russian(self):
|
""""""Checks if file path is russian
|
:return: True iff document has a russian name
|
""""""
|
russian_chars = 0
|
for char in RUSSIAN_CHARS:
|
if char in self.name:
|
russian_chars += 1 # found a russian char
|
return russian_chars > len(RUSSIAN_CHARS) / 2.0"
|
15,"def rename(self, new_path):
|
""""""Renames to new path
|
:param new_path: new path to use
|
""""""
|
rename_path = fix_raw_path(new_path)
|
if is_folder(self.path):
|
os.rename(self.path, rename_path)
|
else:
|
os.renames(self.path, rename_path)"
|
16,"def __start_waiting_for_events(self):
|
'''
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.