Mercurial > mxe-octave
comparison tools/pkg-install.py @ 5210:4eae7db624e8
* tools/pkg-install.py: add rebuild command
author | John Donoghue |
---|---|
date | Tue, 19 Nov 2019 07:57:29 -0500 |
parents | eb8b37422e16 |
children | b6ca48619aa6 |
comparison
equal
deleted
inserted
replaced
5209:6a3f14fd9d0d | 5210:4eae7db624e8 |
---|---|
13 octave_config = "octave-config"; | 13 octave_config = "octave-config"; |
14 make = "make" | 14 make = "make" |
15 verbose = True; | 15 verbose = True; |
16 prefix = ""; | 16 prefix = ""; |
17 pkg = ""; | 17 pkg = ""; |
18 use_pkg_prefix = True; | |
18 arch = ""; | 19 arch = ""; |
19 tmp = "/tmp"; | 20 tmp = "/tmp"; |
20 apiversion = ""; | 21 apiversion = ""; |
21 bin_dir = ""; | 22 bin_dir = ""; |
22 m_dir = ""; | 23 m_dir = ""; |
32 raise Exception, "package is missing file " + f | 33 raise Exception, "package is missing file " + f |
33 | 34 |
34 def get_description(descfile): | 35 def get_description(descfile): |
35 with open(descfile, 'r') as f: | 36 with open(descfile, 'r') as f: |
36 lines = f.read().splitlines() | 37 lines = f.read().splitlines() |
37 d = dict(s.split(': ',1) for s in lines if s.find(': ') != -1) | 38 pat_match = re.compile("(?P<name>[-\w]+):\s*(?P<value>\w.*)") |
39 lineval = "" | |
40 d={} | |
41 for l in lines: | |
42 if len(l) > 0: | |
43 if (l[0] == ' ' or l[0] == '\t'): | |
44 lineval = lineval + l | |
45 else: | |
46 lineval = l | |
47 | |
48 e = pat_match.match(lineval) | |
49 if e: | |
50 d[e.group("name")] = e.group("value") | |
51 | |
38 return d | 52 return d |
39 | 53 |
40 def extract_pkg(filename, nm): | 54 def extract_pkg(filename, nm): |
41 pkg = [] | 55 pkg = [] |
42 with open(filename, 'r') as f: | 56 with open(filename, 'r') as f: |
334 print "cleaning up" | 348 print "cleaning up" |
335 os.chdir(currdir) | 349 os.chdir(currdir) |
336 | 350 |
337 if env.cleanup: | 351 if env.cleanup: |
338 shutil.rmtree(tmpdir) | 352 shutil.rmtree(tmpdir) |
339 | 353 |
354 def fix_depends(deps): | |
355 deplist = [s.strip() for s in deps.split(",") if len(s.strip()) > 0] | |
356 deppat = re.compile('\s*(?P<name>[-\w]+)\s*(\(\s*(?P<op>[<>=]+)\s*(?P<ver>\d+\.\d+(\.\d+)*)\s*\))*\s*') | |
357 deps = [] | |
358 for d in deplist: | |
359 e = deppat.match(d) | |
360 name = e.group("name") | |
361 ver = e.group("ver") | |
362 | |
363 if ver: | |
364 op = e.group("op") | |
365 else: | |
366 op = ">=" | |
367 ver = "0.0.0" | |
368 | |
369 deps.append({"package": name, "operator": op, "version": ver}) | |
370 | |
371 return deps | |
372 | |
373 def rebuild_pkg(env): | |
374 currdir = os.getcwd() | |
375 | |
376 try: | |
377 oct_dir = env.prefix + "/share/octave" | |
378 pkg_dir = oct_dir + "/packages" | |
379 arch_dir = env.prefix + "/lib/octave/packages" | |
380 | |
381 pkg_list_file = oct_dir + "/octave_packages" | |
382 | |
383 descs=glob.glob(pkg_dir + "/*/packinfo/DESCRIPTION") | |
384 | |
385 with open(pkg_list_file, "w") as f: | |
386 f.write("# Created by pkg-install.py\n") | |
387 f.write("# name: global_packages\n") | |
388 f.write("# type: cell\n"); | |
389 f.write("# rows: 1\n") | |
390 f.write("# columns: {}\n".format(len(descs))) | |
391 | |
392 for d in descs: | |
393 pkg = d[len(pkg_dir):-len("/packinfo/DESCRIPTION")] | |
394 if env.verbose: | |
395 print "Rebuilding {}".format(pkg) | |
396 desc = get_description(d) | |
397 desc["Name"] = desc["Name"].lower() | |
398 desc["Depends"] = fix_depends(desc.get("Depends","")) | |
399 | |
400 f.write("# name: <cell-element>\n"); | |
401 f.write("# type: scalar struct\n"); | |
402 f.write("# ndims: 2\n"); | |
403 f.write(" 1 1\n"); | |
404 f.write("# length: 13\n"); | |
405 | |
406 pkg_fields = [ "Name", "Version", "Date", "Author", "Maintainer", \ | |
407 "Title", "Description", "Depends", "Autoload", "License" ] | |
408 for field in pkg_fields: | |
409 name = field.lower() | |
410 value = desc.get(field, None) | |
411 if value is None: | |
412 if name == "autoload": | |
413 value = "no" | |
414 else: | |
415 value = "not set" | |
416 | |
417 f.write("# name: {}\n".format(name)) | |
418 if name == "depends": | |
419 f.write("# type: cell\n") | |
420 f.write("# rows: 1\n") | |
421 f.write("# columns: {}\n".format(len(value))) | |
422 dep_fields = [ "package", "operator", "version" ] | |
423 for dep in value: | |
424 f.write("# name: <cell-element>\n") | |
425 f.write("# type: scalar struct\n") | |
426 f.write("# ndims: 2\n") | |
427 f.write(" 1 1\n"); | |
428 f.write("# length: 3\n"); | |
429 | |
430 for df in dep_fields: | |
431 val = dep.get(df) | |
432 f.write("# name: {}\n".format(df)) | |
433 f.write("# type: sq_string\n") | |
434 f.write("# elements: 1\n") | |
435 f.write("# length: {}\n".format(len(str(val)))) | |
436 f.write("{}\n".format(str(val))) | |
437 f.write("\n\n"); | |
438 | |
439 f.write("\n\n"); | |
440 else: | |
441 f.write("# type: sq_string\n") | |
442 f.write("# elements: 1\n") | |
443 f.write("# length: {}\n".format(len(str(value)))) | |
444 f.write("{}\n".format(str(value))) | |
445 | |
446 f.write("\n\n"); | |
447 | |
448 f.write("# name: loaded\n") | |
449 f.write("# type: bool\n") | |
450 f.write("0\n") | |
451 f.write("\n\n"); | |
452 | |
453 name = "dir" | |
454 if env.use_pkg_prefix: | |
455 value = "__OH__/share/octave/packages" + pkg | |
456 else: | |
457 value = pkg_dir + pkg | |
458 | |
459 f.write("# name: {}\n".format(name)) | |
460 f.write("# type: sq_string\n") | |
461 f.write("# elements: 1\n") | |
462 f.write("# length: {}\n".format(len(str(value)))) | |
463 f.write("{}\n".format(str(value))) | |
464 f.write("\n\n"); | |
465 | |
466 name = "archprefix" | |
467 if env.use_pkg_prefix: | |
468 value = "__OH__/lib/octave/packages" + pkg | |
469 else: | |
470 value = arch_dir + pkg | |
471 f.write("# name: {}\n".format(name)) | |
472 f.write("# type: sq_string\n") | |
473 f.write("# elements: 1\n") | |
474 f.write("# length: {}\n".format(len(str(value)))) | |
475 f.write("{}\n".format(str(value))) | |
476 f.write("\n\n"); | |
477 finally: | |
478 os.chdir(currdir) | |
479 | |
340 | 480 |
341 def pkg (args): | 481 def pkg (args): |
342 arch = '' | 482 arch = '' |
483 operation = "install" | |
343 | 484 |
344 env = Env() | 485 env = Env() |
345 | 486 |
346 files = [] | 487 files = [] |
488 | |
489 operation = args[0] | |
490 if operation != "install" and operation != "rebuild": | |
491 raise Exception, "Expected pkg operation 'install' or 'rebuild'" | |
492 | |
493 | |
494 args = args[1:] | |
347 | 495 |
348 for a in args: | 496 for a in args: |
349 print a | |
350 c=a.split("=") | 497 c=a.split("=") |
351 key=c[0] | 498 key=c[0] |
352 if len(c) > 1: | 499 if len(c) > 1: |
353 val=c[1] | 500 val=c[1] |
354 else: | 501 else: |
356 | 503 |
357 if key == "-verbose": | 504 if key == "-verbose": |
358 env.verbose = True; | 505 env.verbose = True; |
359 elif key == "--verbose": | 506 elif key == "--verbose": |
360 env.verbose = True; | 507 env.verbose = True; |
508 elif key == "--no-pkg-prefix": | |
509 env.use_pkg_prefix = False; | |
361 elif key == "-no-cleanup": | 510 elif key == "-no-cleanup": |
362 env.cleanup = False; | 511 env.cleanup = False; |
363 elif val == "": | 512 elif val == "": |
364 files.append(key) | 513 files.append(key) |
365 | 514 |
404 env.arch = os.popen(env.octave_config + " -p CANONICAL_HOST_TYPE").read().rstrip("\r\n") | 553 env.arch = os.popen(env.octave_config + " -p CANONICAL_HOST_TYPE").read().rstrip("\r\n") |
405 env.apiversion = os.popen(env.octave_config + " -p API_VERSION").read().rstrip("\r\n") | 554 env.apiversion = os.popen(env.octave_config + " -p API_VERSION").read().rstrip("\r\n") |
406 env.bindir = os.popen(env.octave_config + " -p BINDIR").read().rstrip("\r\n") | 555 env.bindir = os.popen(env.octave_config + " -p BINDIR").read().rstrip("\r\n") |
407 | 556 |
408 if env.verbose: | 557 if env.verbose: |
558 print "operation=", operation | |
409 print "mkoctfile=", env.mkoctfile | 559 print "mkoctfile=", env.mkoctfile |
410 print "arch=", env.arch | 560 print "arch=", env.arch |
411 print "apiversion=", env.apiversion | 561 print "apiversion=", env.apiversion |
412 print "prefix=", env.prefix | 562 print "prefix=", env.prefix |
413 print "files=", files | 563 print "files=", files |
414 print "verbose=", env.verbose | 564 print "verbose=", env.verbose |
415 | 565 |
416 for a in files: | 566 if operation == "install": |
417 install_pkg(a, env) | 567 for a in files: |
418 | 568 install_pkg(a, env) |
569 # rebuild pkg list afterwards | |
570 rebuild_pkg(env) | |
571 else: | |
572 rebuild_pkg(env) | |
419 return 0 | 573 return 0 |
420 | 574 |
421 if __name__ == "__main__": | 575 if __name__ == "__main__": |
422 if len(sys.argv) > 1: | 576 if len(sys.argv) > 1: |
423 pkg(sys.argv[1:]) | 577 pkg(sys.argv[1:]) |