You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
IMM-Internet-Media-Manager/Code/IMM/GeneralFunctions/DataStructureManupulations.py

56 lines
1.5 KiB
Python

from sys import platform as OperatingSystem
Quotes = '"\''
if OperatingSystem == "win32":
PathSlash = '\\'
else:
PathSlash = '/'
FileProtocol = "file:" + 2*PathSlash
def ConvertToStandardPathFormat(Path):
""" Example,
Input: '"file:///some/path/somefile.extension"
Output: /some/path/somefile.extension
"""
Path = Path.strip(Quotes)
if Path.startswith(FileProtocol):
Path = Path[len(FileProtocol):]
return Path
def GetTextAfter(Text, ReadlinesTextFile):
for Lines in range(len(ReadlinesTextFile)):
Line = ReadlinesTextFile[Lines].strip('\n')
if Line.startswith(Text):
return Line[len(Text):]
return ''
def SingleQuoteString(String):
if len(String) > 0:
if String[0] != '\'' or String[-1] != '\'':
String = '\'' + String + '\''
return String
def DoubleQuoteString(String):
if len(String) > 0:
if String[0] != '"' or String[-1] != '"':
String = '"' + String + '"'
return String
def ListIntoString(List, QuoteItems=0, Seprator=' '):
if QuoteItems == 2:
for i in range(len(List)):
Quoteditem = DoubleQuoteString(List[i])
List[i] = Quoteditem
elif QuoteItems == 1:
for i in range(len(List)):
Quoteditem = SingleQuoteString(List[i])
List[i] = Quoteditem
Stringoflist = (Seprator).join(List)
return Stringoflist
def StandardVariableName(Variable):
Variable = Variable.casefold()
Variable = Variable.replace('_', '').replace(' ', '')
return Variable