~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/utilities/js/jsbuild.py

Merged in Ian's branch, and updated pkg_src stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
HERE = os.path.dirname(__file__)
19
19
BUILD_DIR = os.path.normpath(os.path.join(HERE, '..', '..', '..', 'build'))
20
 
DEFAULT_SRC_DIR = os.path.normpath(os.path.join(HERE, '..', '..', '..'))
21
 
PKG_SRC_DIR = pkg_resources.resource_filename(
22
 
    pkg_resources.Requirement.parse("lazr-js"), "lazrjs")
 
20
DEFAULT_SRC_DIR = os.path.normpath(os.path.join(HERE, '..', '..', '..', 'app', 'javascript'))
23
21
 
24
22
ESCAPE_STAR_PROPERTY_RE = re.compile(r'\*([a-zA-Z0-9_-]+):')
25
23
UNESCAPE_STAR_PROPERTY_RE = re.compile(r'([a-zA-Z0-9_-]+)_ie_star_hack:')
189
187
 
190
188
class Builder:
191
189
 
192
 
    def __init__(self, name='lazr', build_dir=BUILD_DIR, src_dir=PKG_SRC_DIR,
193
 
                 extra_files=None, exclude_regex='', file_type='raw',
194
 
                 copy_yui_to=BUILD_DIR):
 
190
    def __init__(self, name='lazr', build_dir=BUILD_DIR, src_dir=DEFAULT_SRC_DIR,
 
191
                 extra_files=None, exclude_regex='', file_type='raw'):
195
192
        """Create a new Builder.
196
193
 
197
194
        :param name: The name of the package we are building. This will
207
204
            file.  Possible values are 'raw', 'min', and 'debug'.  File types
208
205
            are identified by their basename suffix: foo.js, foo-min.js,
209
206
            foo-debug.js, etc.
210
 
        :param copy_yui_to: The absolute path (as a string) to the place where
211
 
            the YUI modules should be copied to. Defaults to BUILD_DIR.
212
207
        """
213
208
        self.name = name
214
209
        self.build_dir = build_dir
227
222
 
228
223
        self.exclusion_regex = exclude_regex
229
224
        self.file_type = file_type
230
 
        self.copy_yui_to = copy_yui_to
231
225
 
232
226
        self.log("Using filter: " + self.file_type)
233
227
 
417
411
                continue
418
412
            yield name, path
419
413
 
420
 
    def copy_yui_package(self):
421
 
        """Copy the contents of our 'yui' dir to self.copy_yui_to."""
422
 
        yui_dirs = glob(os.path.join(self.src_dir, 'yui') + '/*')
423
 
        for dir in yui_dirs:
424
 
            dir_name = os.path.split(dir)[-1]
425
 
            dst_dir = os.path.join(self.copy_yui_to, dir_name)
426
 
            if not os.path.isdir(dst_dir):
427
 
                shutil.copytree(dir, dst_dir)
428
 
 
429
414
    def do_build(self):
430
 
        self.copy_yui_package()
431
415
        for name, cpath in self.find_components():
432
416
            files_to_link = glob(os.path.join(cpath, '*.js'))
433
417
            if len(files_to_link) == 0:
458
442
        '-b', '--builddir', dest='build_dir', default=BUILD_DIR,
459
443
        help=('The directory that should contain built files.'))
460
444
    parser.add_option(
461
 
        '-s', '--srcdir', dest='src_dir', default=PKG_SRC_DIR,
 
445
        '-s', '--srcdir', dest='src_dir', default=DEFAULT_SRC_DIR,
462
446
        help=('The directory containing the src files.'))
463
447
    parser.add_option(
464
448
        '-x', '--exclude', dest='exclude', default='',
469
453
        help=('Only bundle files in the source directory that match the '
470
454
              'specified file-type filter. Possible values are '
471
455
              '[min, raw, debug]. [default: %default]'))
472
 
    parser.add_option(
473
 
        '-c', '--copy-yui-to', dest='copy_yui_to', default=BUILD_DIR,
474
 
        help=('Copy the YUI tree to the given directory before building'))
475
456
    return parser.parse_args()
476
457
 
477
458
 
478
459
def main():
479
 
   options, extra= get_options()
480
 
   Builder(
 
460
    options, extra= get_options()
 
461
 
 
462
    Builder(
481
463
       name=options.name,
482
464
       build_dir=options.build_dir,
483
465
       src_dir=options.src_dir,
484
466
       extra_files=extra,
485
467
       exclude_regex=options.exclude,
486
468
       file_type=options.file_type,
487
 
       copy_yui_to=options.copy_yui_to,
488
469
       ).do_build()