1. Written portable CopyFile() & used in extractData.copyBundle() 2. Renamed GeneralFunctions to portableCode for better clarity that it can be used in any software and not specific to this program
This commit is contained in:
parent
c24ea8311d
commit
25a2c214fa
@ -1,18 +0,0 @@
|
||||
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):
|
||||
if not os.path.isdir(Directory):
|
||||
os.mkdir(Directory)
|
||||
return True
|
||||
else:
|
||||
return False
|
@ -14,14 +14,17 @@ import sys
|
||||
from urllib.parse import quote as strToHtmlFmt
|
||||
import zipfile
|
||||
|
||||
from GeneralFunctions.DataStructureManipulations import (
|
||||
from portableCode.DataStructureManipulations import (
|
||||
StrListToDictionary
|
||||
)
|
||||
from GeneralFunctions.InputOutput import (
|
||||
from portableCode.InputOutput import (
|
||||
WriteTextFiles,
|
||||
WriteBinaryToFile
|
||||
)
|
||||
from GeneralFunctions.OS import CreateDir
|
||||
from portableCode.OS import (
|
||||
CreateDir,
|
||||
CopyFile
|
||||
)
|
||||
|
||||
|
||||
""" FIXME: paths hard coded UNIX style & most likely will not work on Windows.
|
||||
@ -40,20 +43,7 @@ class extractData:
|
||||
|
||||
def copyBundle(self, source, activityName):
|
||||
destination = self.websiteDir+"bundles/"+activityName+".xo"
|
||||
# move this code block to a portable function
|
||||
# copyFile(source, destination)
|
||||
try:
|
||||
# hard link if on same partition
|
||||
os.link(source, destination)
|
||||
except FileExistsError:
|
||||
# FIXME: create a portable function to compare if two files
|
||||
# are same and use it here
|
||||
pass
|
||||
except OSError:
|
||||
# copy if on different partition
|
||||
shutil.copy2(source, destination)
|
||||
except Exception as unknownError:
|
||||
raise unknownError
|
||||
CopyFile(source, destination)
|
||||
|
||||
def createDirectories(self):
|
||||
assert CreateDir(self.websiteDir+"app")
|
||||
|
36
generator/portableCode/OS.py
Normal file
36
generator/portableCode/OS.py
Normal file
@ -0,0 +1,36 @@
|
||||
import os
|
||||
|
||||
|
||||
def CallFuncInDir(Directory, Function, *args, **kwArgs):
|
||||
CurrentDir = os.getcwd()
|
||||
os.chdir(Directory)
|
||||
Function(*args, **kwArgs)
|
||||
os.chdir(CurrentDir)
|
||||
|
||||
|
||||
def CreateDir(Directory):
|
||||
""" return True if operation succesful and False if failed """
|
||||
if not os.path.isfile(Directory):
|
||||
if not os.path.isdir(Directory):
|
||||
os.mkdir(Directory)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def CopyFile(Source, Destination):
|
||||
""" raises exception if fails.
|
||||
Implement exception handling else program will abort.
|
||||
"""
|
||||
try:
|
||||
# hard link if on same partition
|
||||
os.link(Source, Destination)
|
||||
except FileExistsError:
|
||||
# FIXME: create a function to compare if two files
|
||||
# are same and use it here
|
||||
pass
|
||||
except OSError:
|
||||
# copy if on different partition
|
||||
shutil.copy2(Source, Destination)
|
||||
except Exception as unknownError:
|
||||
raise unknownError
|
Loading…
Reference in New Issue
Block a user