Skip to content

Instantly share code, notes, and snippets.

Created September 20, 2010 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/588026 to your computer and use it in GitHub Desktop.
Save anonymous/588026 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding=utf-8
"""
Generate all the modules of the projects as SCORM2004r3 packages that match a
pattern.
This script work if your project as the following structure:
0123_project_root/ # 0123 = customer code
|-- .svn
|-- 0123_M01 # module 01
| |-- .svn
| |-- 0123_M01_SCO1 # SCO 1.1
| | |-- .svn
| |-- 0123_M01_SCO2 # SCO 1.2
| | |-- .svn
| |-- 0123_M01_SCO3 # SCO 1.3
| | |-- .svn
| |-- 0123_M01_SCO4 # SCO 1.4
| | |-- .svn
| |-- imsmanifest.xml # scorm support files
| |-- ...
|-- 0123_M02 # module 02
...
|-- 0123_M10 # module 10
|-- _src
|-- _classes # Flash classes used form this project
You want to be able to export one or all modules at one, without .svn folders
and other developpements files.
"""
import os, sys, getopt, glob, zipfile
EXCLUDED = ('..',
'*.kpf', '*.komodoproject', # komodo
'_src', # studio
'__MACOSX', '.DS_Store', # MacOS
'Thumbs.db', # Windows
'.svn', # svn
'.hg', '.hgignore', '.hgtags', # Mercurial
'.git', '.gitignore' # git
)
def browse(path):
if os.path.isdir(path) and not path in EXCLUDED:
for root, dirs, files in os.walk(path):
for file in files:
if not file in EXCLUDED:
yield (os.path.join(root, file))
for dir in dirs:
if dir in EXCLUDED:
dirs.remove(dir)
def main(argv):
"""
Initialize the script
"""
try:
opts, args = getopt.gnu_getopt(argv, "h:p", ["help", "pattern="])
except getopt.GetoptError:
usage()
sys.exit(2)
pattern = None
for opt, arg in opts:
if opt == '--pattern' or opt == '-p':
pattern = arg
validate(pattern)
zip(pattern)
def usage():
print 'Generate all the modules of the projects as SCORM2004r3 packages.'
print ' ~ python publish_all.py --pattern=123_M01*'
def validate(pattern):
""" Validate the required variables and check if they are correctly set."""
if pattern is None:
print 'The `pattern` is required.'
sys.exit(2)
def zip(pattern):
for path in glob.glob(pattern):
if os.path.isdir(path):
zip = zipfile.ZipFile('%s.zip' % path, mode = 'w')
for file in browse(path):
zip.write(file)
zip.close()
print '%s.zip generated' % path
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment