Include persoconf own dir in packages
parent
755b079ab6
commit
d54b818a2e
|
@ -5,6 +5,8 @@ import os.path
|
||||||
import time
|
import time
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
|
import utils
|
||||||
|
|
||||||
from metafile import Metafile, MalformedMetafileError
|
from metafile import Metafile, MalformedMetafileError
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
@ -30,6 +32,11 @@ def init(parser):
|
||||||
default="persoconf." + (time.strftime("%Y%m%d")),
|
default="persoconf." + (time.strftime("%Y%m%d")),
|
||||||
help="The name of the package to create" )
|
help="The name of the package to create" )
|
||||||
|
|
||||||
|
parser.add_argument( "--nopersoconf", "-n",
|
||||||
|
action="store_true",
|
||||||
|
help="Do not include persoconf own config " \
|
||||||
|
"directory in the resulting package" )
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
def run(args, persoconf, logger):
|
def run(args, persoconf, logger):
|
||||||
|
|
||||||
|
@ -46,12 +53,14 @@ def run(args, persoconf, logger):
|
||||||
# Load app META file
|
# Load app META file
|
||||||
try:
|
try:
|
||||||
appmetas.append(
|
appmetas.append(
|
||||||
Metafile(json_path = os.path.join(
|
Metafile(
|
||||||
|
json_path = os.path.join(
|
||||||
persoconf.path,
|
persoconf.path,
|
||||||
app,
|
app,
|
||||||
persoconf.metafile)
|
persoconf.metafile
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger.warning( "Metafile %s does not exist for app %s; ignoring"
|
logger.warning( "Metafile %s does not exist for app %s; ignoring"
|
||||||
|
@ -68,7 +77,7 @@ def run(args, persoconf, logger):
|
||||||
# Adds the app name if there is only one packaged
|
# Adds the app name if there is only one packaged
|
||||||
if len(appmetas) == 1:
|
if len(appmetas) == 1:
|
||||||
pkgname += ("." + appmetas[0].name)
|
pkgname += ("." + appmetas[0].name)
|
||||||
|
|
||||||
# Switch according to the pkgtype
|
# Switch according to the pkgtype
|
||||||
if args.pkgtype == "tgz":
|
if args.pkgtype == "tgz":
|
||||||
|
|
||||||
|
@ -76,20 +85,55 @@ def run(args, persoconf, logger):
|
||||||
|
|
||||||
# Create a tar containing the files in the right place
|
# Create a tar containing the files in the right place
|
||||||
pkg = tarfile.open(pkgname, "w:gz")
|
pkg = tarfile.open(pkgname, "w:gz")
|
||||||
|
|
||||||
for appmeta in appmetas:
|
for appmeta in appmetas:
|
||||||
|
|
||||||
|
# Add META file to the archive
|
||||||
|
if not args.nopersoconf:
|
||||||
|
filename_meta = os.path.join( persoconf.path,
|
||||||
|
appmeta.name,
|
||||||
|
persoconf.metafile )
|
||||||
|
filedest_meta = utils.contractuser( filename_meta )
|
||||||
|
|
||||||
|
if filedest_meta.startswith("~/"):
|
||||||
|
filedest_meta = filedest_meta[2:]
|
||||||
|
|
||||||
|
try:
|
||||||
|
pkg.add(filename_meta, arcname=filedest_meta)
|
||||||
|
logger.info(
|
||||||
|
"Adding app %s to package".format(appmeta.name)
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(
|
||||||
|
"Failed to add app {app} to tar package {pkg}: {err}" \
|
||||||
|
.format( app = appmeta.name,
|
||||||
|
pkg = pkgname,
|
||||||
|
err = str(e) )
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
for f in appmeta.files:
|
for f in appmeta.files:
|
||||||
filename = persoconf.path +"/"+ appmeta.name +"/"+ f
|
filename = os.path.join( persoconf.path,
|
||||||
filedest = appmeta.files[f]["dest"]
|
appmeta.name,
|
||||||
|
f )
|
||||||
|
filedest = appmeta.files[f]["dest"]
|
||||||
|
filedest_pc = utils.contractuser( filename )
|
||||||
|
|
||||||
# Remove possible 'home'. The final targz should be extracted
|
# Remove possible 'home'. The final targz should be extracted
|
||||||
# at $HOME.
|
# at $HOME.
|
||||||
if filedest.startswith("~/"):
|
if filedest.startswith("~/"):
|
||||||
filedest = filedest[2:]
|
filedest = filedest[2:]
|
||||||
|
if filedest_pc.startswith("~/"):
|
||||||
|
filedest_pc = filedest_pc[2:]
|
||||||
|
|
||||||
# TODO save and restore owners and permissions
|
# TODO save and restore owners and permissions
|
||||||
try:
|
try:
|
||||||
pkg.add(filename, arcname=filedest)
|
pkg.add(filename, arcname=filedest)
|
||||||
|
|
||||||
|
if not args.nopersoconf:
|
||||||
|
pkg.add(filename, arcname=filedest_pc)
|
||||||
|
|
||||||
logger.info("Adding %s to package" % f)
|
logger.info("Adding %s to package" % f)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Reference in New Issue