Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
141
Merge Requests
141
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
erp5
Commits
39c5c1a4
Commit
39c5c1a4
authored
Jan 17, 2017
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bt5_prototype: Add BusinessPackageTarball file
parent
826c3185
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
3 deletions
+62
-3
product/ERP5/Document/BusinessPackage.py
product/ERP5/Document/BusinessPackage.py
+62
-3
No files found.
product/ERP5/Document/BusinessPackage.py
View file @
39c5c1a4
...
...
@@ -35,6 +35,8 @@ import hashlib
import
posixpath
import
transaction
import
imghdr
import
tarfile
import
time
from
copy
import
deepcopy
from
collections
import
defaultdict
from
cStringIO
import
StringIO
...
...
@@ -189,13 +191,18 @@ class BusinessPackage(XMLObject):
"""
if
not
self
.
getBuildingState
()
==
'built'
:
raise
BusinessPackageException
,
'Package not built properly'
self
.
_export
(
path
,
local
,
bpa
)
return
self
.
_export
(
path
,
local
,
bpa
)
def
_export
(
self
,
path
=
None
,
local
=
0
,
bpa
=
None
):
if
bpa
is
None
:
if
local
:
# we export into a folder tree
bpa
=
BusinessPackageFolder
(
path
,
creation
=
1
)
else
:
# We export BP into a tarball file
if
path
is
None
:
path
=
self
.
getTitle
()
bpa
=
BusinessPackage
Folder
(
path
,
creation
=
1
)
bpa
=
BusinessPackage
Tarball
(
path
,
creation
=
1
)
# export bt
for
prop
in
self
.
propertyMap
():
...
...
@@ -226,7 +233,8 @@ class BusinessPackage(XMLObject):
"""
Import all xml files in Business Template
"""
bpa
=
BusinessPackageFolder
(
path
,
importing
=
1
)
bpa
=
(
BusinessPackageFolder
if
os
.
path
.
isdir
(
path
)
else
BusinessPackageTarball
)(
path
,
importing
=
1
)
bp_item
=
bp
()
bpa
.
importFiles
(
bp_item
)
prop_dict
=
{}
...
...
@@ -332,6 +340,57 @@ class BusinessPackageFolder(BusinessPackageArchive):
cache_database
.
db
.
close
()
del
cache_database
.
db
class
BusinessPackageTarball
(
BusinessPackageArchive
):
"""
Class archiving businnes package into a tarball file
"""
def
__init__
(
self
,
path
,
creation
=
0
,
importing
=
0
,
**
kw
):
super
(
BusinessPackageTarball
,
self
).
__init__
(
path
,
**
kw
)
if
creation
:
self
.
fobj
=
StringIO
()
self
.
tar
=
tarfile
.
open
(
''
,
'w:gz'
,
self
.
fobj
)
self
.
time
=
time
.
time
()
elif
importing
:
self
.
tar
=
tarfile
.
open
(
path
,
'r:gz'
)
self
.
item_dict
=
item_dict
=
defaultdict
(
list
)
for
info
in
self
.
tar
.
getmembers
():
if
info
.
isreg
():
path
=
info
.
name
.
split
(
'/'
)
if
path
[
0
]
==
'.'
:
del
path
[
0
]
item_dict
[
path
[
1
]].
append
((
'/'
.
join
(
path
[
2
:]),
info
))
def
_writeFile
(
self
,
obj
,
path
):
if
self
.
path
:
path
=
posixpath
.
join
(
self
.
path
,
path
)
info
=
tarfile
.
TarInfo
(
path
)
info
.
mtime
=
self
.
time
obj
.
seek
(
0
,
2
)
info
.
size
=
obj
.
tell
()
obj
.
seek
(
0
)
self
.
tar
.
addfile
(
info
,
obj
)
def
finishCreation
(
self
):
self
.
tar
.
close
()
return
self
.
fobj
def
importFiles
(
self
,
item
):
"""
Import all file from the archive to the site
"""
extractfile
=
self
.
tar
.
extractfile
item_name
=
item
.
__class__
.
__name__
for
file_name
,
info
in
self
.
item_dict
.
get
(
item_name
,
()):
if
'%'
in
file_name
:
file_name
=
unquote
(
file_name
)
elif
item_name
==
'bt'
and
file_name
==
'revision'
:
continue
f
=
extractfile
(
info
)
self
.
revision
.
hash
(
item_name
+
'/'
+
file_name
,
f
.
read
())
f
.
seek
(
0
)
item
.
_importFile
(
file_name
,
f
)
class
bp
(
dict
):
"""Fake 'bp' item to read bp/* files through BusinessPackageArchive"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment