Formatted python code using flake8 w/ default configuration
This commit is contained in:
@@ -8,6 +8,7 @@ else:
|
||||
PathSlash = '/'
|
||||
FileProtocol = "file:" + 2*PathSlash
|
||||
|
||||
|
||||
def ConvertToStandardPathFormat(Path):
|
||||
""" Example,
|
||||
Input: '"file:///some/path/somefile.extension"
|
||||
@@ -18,6 +19,7 @@ def ConvertToStandardPathFormat(Path):
|
||||
Path = Path[len(FileProtocol):]
|
||||
return Path
|
||||
|
||||
|
||||
def GetTextAfter(Text, ReadlinesTextFile):
|
||||
for Lines in range(len(ReadlinesTextFile)):
|
||||
Line = ReadlinesTextFile[Lines].strip('\n')
|
||||
@@ -25,18 +27,21 @@ def GetTextAfter(Text, ReadlinesTextFile):
|
||||
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)):
|
||||
@@ -49,36 +54,42 @@ def ListIntoString(List, QuoteItems=0, Seprator=' '):
|
||||
Stringoflist = (Seprator).join(List)
|
||||
return Stringoflist
|
||||
|
||||
|
||||
# strip=0 => remove both ' & ", 1 => remove ', 2 => remove "
|
||||
def UnquoteString(String, strip=0):
|
||||
while True:
|
||||
if (
|
||||
strip != 2
|
||||
and String.startswith('"')
|
||||
and String.endswith('"')):
|
||||
strip != 2 and
|
||||
String.startswith('"') and
|
||||
String.endswith('"')
|
||||
):
|
||||
String = String.strip('"')
|
||||
elif (
|
||||
strip != 1
|
||||
and String.startswith("'")
|
||||
and String.endswith("'")):
|
||||
and String.endswith("'")
|
||||
):
|
||||
String = String.strip("'")
|
||||
else:
|
||||
break
|
||||
return String
|
||||
|
||||
|
||||
def StandardVariableName(Variable):
|
||||
Variable = Variable.casefold()
|
||||
Variable = Variable.replace('_', '').replace(' ', '')
|
||||
return Variable
|
||||
|
||||
#def DictionaryToJsonStr(Dict, BaseIndentation=0):
|
||||
#BI = '\t'*BaseIndentation
|
||||
#JsonStr = BI+'{\n'
|
||||
#for k, v in Dict.items():
|
||||
#JsonStr += BI+'\t"'+k+'" : "'+v+'",\n'
|
||||
#JsonStr = JsonStr[:-2]
|
||||
#JsonStr += '\n'+BI+'}'
|
||||
#return JsonStr
|
||||
"""
|
||||
def DictionaryToJsonStr(Dict, BaseIndentation=0):
|
||||
BI = '\t'*BaseIndentation
|
||||
JsonStr = BI+'{\n'
|
||||
for k, v in Dict.items():
|
||||
JsonStr += BI+'\t"'+k+'" : "'+v+'",\n'
|
||||
JsonStr = JsonStr[:-2]
|
||||
JsonStr += '\n'+BI+'}'
|
||||
return JsonStr
|
||||
"""
|
||||
|
||||
def StringToKeyValuePair(String, Seprator):
|
||||
SepratorAt = String.find(Seprator)
|
||||
@@ -89,14 +100,17 @@ def StringToKeyValuePair(String, Seprator):
|
||||
else:
|
||||
return "", String
|
||||
|
||||
|
||||
def FormatStrForDictinary(String):
|
||||
String = String.strip(" \n\r")
|
||||
return UnquoteString(String)
|
||||
|
||||
|
||||
def StrListToDictionary(
|
||||
List,
|
||||
Seprator = '=',
|
||||
FormatFunction = FormatStrForDictinary):
|
||||
Seprator='=',
|
||||
FormatFunction=FormatStrForDictinary
|
||||
):
|
||||
Dictionary = {}
|
||||
for i in List:
|
||||
k, v = StringToKeyValuePair(i, Seprator)
|
||||
|
||||
@@ -2,6 +2,7 @@ from os.path import isfile as DoesFileExist
|
||||
|
||||
from .DataStructureManupulations import ConvertToStandardPathFormat
|
||||
|
||||
|
||||
def ReadTextFile(FilePath):
|
||||
FilePath = ConvertToStandardPathFormat(FilePath)
|
||||
if DoesFileExist(FilePath) is True:
|
||||
@@ -11,11 +12,13 @@ def ReadTextFile(FilePath):
|
||||
return ReadFile
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
def ReadlinesTextFile(FilePath):
|
||||
String = ReadTextFile(FilePath)
|
||||
return String.split('\n')
|
||||
|
||||
|
||||
def WriteTextFiles(FilePath, Text):
|
||||
if type(Text) != str:
|
||||
Text = '\n'.join(Text)
|
||||
@@ -23,7 +26,8 @@ def WriteTextFiles(FilePath, Text):
|
||||
File.write(Text)
|
||||
File.close()
|
||||
|
||||
|
||||
def WriteBinaryToFile(Filepath, Data):
|
||||
File=open(Filepath, 'wb')
|
||||
File = open(Filepath, 'wb')
|
||||
File.write(Data)
|
||||
File.close()
|
||||
|
||||
@@ -3,6 +3,6 @@ from urllib.request import urlopen
|
||||
|
||||
HttpsContext = ssl.create_default_context()
|
||||
|
||||
|
||||
def Download(Url):
|
||||
return urlopen(Url, context=HttpsContext).read()
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import os
|
||||
|
||||
|
||||
def CallFuncInDir(Directory, Function, *args, **kwArgs):
|
||||
CurrentDir = os.getcwd()
|
||||
os.chdir(Directory)
|
||||
Function(*args, **kwArgs)
|
||||
os.chdir(CurrentDir)
|
||||
|
||||
|
||||
# return True if operation succesful and False if failed
|
||||
def CreateDir(Directory):
|
||||
if not os.path.isfile(Directory):
|
||||
|
||||
Reference in New Issue
Block a user