Skip to content

Commit bb02c42

Browse files
committed
add exportconfigjs command
1 parent fa6149b commit bb02c42

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

uliweb/manage.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,59 @@ def process_file(self, sfile, dpath, dfile):
527527
print 'Compress %s to %s' % (sfile, dfile)
528528
return True
529529
register_command(ExportStaticCommand)
530-
530+
531+
532+
class ExportconfigjsCommand(Command):
533+
#change the name to real command name, such as makeapp, makeproject, etc.
534+
name = 'exportconfigjs'
535+
#command line parameters definition
536+
option_list = (
537+
make_option('-d', '--directory', dest='directory', default='.',
538+
help='Output config.js to this directory.'),
539+
make_option('-a', '--app', dest='app', default='',
540+
help='Output config.js to this appname/static.'),
541+
)
542+
#help information
543+
help = 'Export requirejs config.js. If no filename, it will be config.js'
544+
#args information, used to display show the command usage message
545+
args = '[filename]'
546+
#if True, it'll check the current directory should has apps directory
547+
check_apps_dirs = True
548+
#if True, it'll check args parameters should be valid apps name
549+
check_apps = False
550+
#if True, it'll skip not predefined parameters in options_list, otherwise it'll
551+
#complain not the right parameters of the command, it'll used in subcommands or
552+
#passing extra parameters to a special command
553+
skip_options = False
554+
#if inherit the base class option_list, default True is inherit
555+
options_inherit = True
556+
557+
558+
def handle(self, options, global_options, *args):
559+
self.get_application(global_options)
560+
561+
from uliweb import application, settings, get_app_dir
562+
563+
if args:
564+
fname = args[0]
565+
else:
566+
fname = 'config.js'
567+
filename = application.get_file(fname, dir='template_files')
568+
path = []
569+
if options.app:
570+
path.append(os.path.join(get_app_dir(options.app), 'static'))
571+
path.append(options.directory)
572+
path.append(fname)
573+
o_filename = os.path.join(*path)
574+
dir = os.path.dirname(o_filename)
575+
if not os.path.exists(dir):
576+
os.makedirs(dir)
577+
with open(o_filename, 'w') as f:
578+
f.write(application.template(filename, {'modules':settings.UI_MODULES}))
579+
print 'Output config file to {}'.format(o_filename)
580+
register_command(ExportconfigjsCommand)
581+
582+
531583
class ExportCommand(Command):
532584
name = 'export'
533585
help = 'Export all installed apps or specified module source files to output directory.'

0 commit comments

Comments
 (0)