Пример #1
0
 def test_find_root_from_within(self):
     root = _makeroot('/a/b.c.d/')
     self.assertEquals(root, sandbox.find_root_from_within('/a/b.c.d'))
     self.assertEquals(root, sandbox.find_root_from_within('/a/b.c.d/x'))
     self.assertEquals(root, sandbox.find_root_from_within('/a/b.c.d/x/y/z'))
     self.assertEquals(root, sandbox.find_root_from_within('/a/b.c.d/'))
     self.assertEquals(None, sandbox.find_root_from_within('/a/bcd/x'))
Пример #2
0
def update_program_if_needed(silent=False):
    '''
    See if sadm itself needs to be updated.
    '''
    # Don't do anything if we're running from within a sandbox.
    if sandbox.find_root_from_within(APP_FOLDER):
        return
    # If this folder has any kind of relationship with a repo...
    if vcs.folder_is_tied_to_vcs(APP_FOLDER):
        try:
            status = vcs.get_status(APP_FOLDER, status_filter=lambda lbl: lbl!= 'unknown', revision=-1)
        except:
            eprintc("Status of sadm can't be determined (is the network down?). Skipping update.", WARNING_COLOR)
            return
        if status:
            # See if there are any items at a status that will prevent success of update.
            bad_status = [x for x in status.keys() if x not in 'modified|removed|added|renamed|kind changed']
            if bad_status:
                eprintc('''
The master version of sadm has changed, but automatic update is impossible. Do
a manual bzr up to resolve the following issues:
''', ERROR_COLOR)
                print(aggregate_vcs.format_aspect_status(None, None, "sadm", status))
                return
            err = vcs.update_checkout(APP_FOLDER)
            if err:
                print('Unable to update sadm; exit code %d from "bzr up" command. Try running "bzr up" manually.' % err)
                return
            return True
        elif not silent:
            print("Sadm is up to date.")
    else:
        if not silent:
            print("This copy of %s doesn't run from a directory that's connected to bzr." % APP_CMD)
Пример #3
0
def update_program_if_needed(silent=False):
    '''
    See if sadm itself needs to be updated.
    '''
    # Don't do anything if we're running from within a sandbox.
    if sandbox.find_root_from_within(APP_FOLDER):
        return
    # If this folder has any kind of relationship with a repo...
    if vcs.folder_is_tied_to_vcs(APP_FOLDER):
        try:
            status = vcs.get_status(APP_FOLDER,
                                    status_filter=lambda lbl: lbl != 'unknown',
                                    revision=-1)
        except:
            eprintc(
                "Status of sadm can't be determined (is the network down?). Skipping update.",
                WARNING_COLOR)
            return
        if status:
            # See if there are any items at a status that will prevent success of update.
            bad_status = [
                x for x in status.keys()
                if x not in 'modified|removed|added|renamed|kind changed'
            ]
            if bad_status:
                eprintc(
                    '''
The master version of sadm has changed, but automatic update is impossible. Do
a manual bzr up to resolve the following issues:
''', ERROR_COLOR)
                print(
                    aggregate_vcs.format_aspect_status(None, None, "sadm",
                                                       status))
                return
            err = vcs.update_checkout(APP_FOLDER)
            if err:
                print(
                    'Unable to update sadm; exit code %d from "bzr up" command. Try running "bzr up" manually.'
                    % err)
                return
            return True
        elif not silent:
            print("Sadm is up to date.")
    else:
        if not silent:
            print(
                "This copy of %s doesn't run from a directory that's connected to bzr."
                % APP_CMD)
Пример #4
0
def main(argv):
    # see if we're supposed to run this command against a different sandbox.
    sbspec = '.'
    del argv[0]
    if len(argv) >= 2:
        first = argv[0]
        if first == '-s':
            del argv[0]
            sbspec = argv[0]
            del argv[0]
        elif first.startswith('--sandbox') or first.startswith('--sb'):
            del argv[0]
            if '=' in first:
                sbspec = first.split('=')[1]
            else:
                sbspec = argv[0]
                del argv[0]

    # check to see if we have enough args.
    if len(argv) < 1:
        supported_verbs = _verb_to_cmd.keys()[:]
        supported_verbs.sort()
        supported_verbs = '|'.join(supported_verbs)
        supported_verbs = '(sandbox_property)|' + supported_verbs
        print('sbverb [-s <sandbox_spec>] %s [args]' % supported_verbs)
        return 1

    # Look up the script that corresponds to our verb.
    verb = argv[0].lower()
    script_args = argv[1:]
    script = _verb_to_cmd.get(verb, None)
    if not script:
        if _BZR_VERBS.match(verb):
            print('This looks like a bzr command.')
            sys.exit(1)
        if _SADM_VERBS.match(verb):
            print('This looks like a sadm command.')
            sys.exit(1)
        script = 'sandbox.py'
        script_args.insert(0, verb)

    # Now find the sandbox to which we're supposed to apply the verb.
    if sbspec == '.':
        root = sandbox.find_root_from_within(sbspec)
        if root:
            sandboxes = [sandbox.Sandbox(root)]
        else:
            print('%s is not within a sandbox.' % os.path.abspath('.'))
            return 1
    else:
        sandboxes = sadm._match_sandboxes('path', None, sbspec)
    if sandboxes:
        if len(sandboxes) == 1:
            sb = sandboxes[0]
            if verb == 'verify' and sb.get_sandboxtype().get_do_quick_build(
            ) and '--quick' not in script_args:
                script_args.append('--quick')
            if not sb.get_sandboxtype().get_do_quick_build(
            ) and '--quick' in script_args:
                script_args.remove('--quick')
            # Split cmd into script file and rest.
            i = script.find(' ')
            if i > -1:
                rest = script[i:]
                script = script[0:i]
            else:
                rest = ''

            # Now look for the appropriate buildscript .py file.
            script = os.path.join(sb.get_code_root(), 'buildscripts', script)
            if os.path.isfile(script):
                # Make sure we're using backslashes on Windows.
                if os.name == 'nt':
                    script = script.replace('/', '\\')
                # Quote if path has spaces.
                if ' ' in script:
                    script = '"%s"' % script
                script += rest
                # Re-quote any args that contain spaces
                for i in range(len(script_args)):
                    if ' ' in script_args[i] and not script_args[i].startswith(
                            '"'):
                        script_args[i] = '"%s"' % script_args[i]
                # Now run the script and report its exit code.
                cmd = 'python %s %s' % (script, ' '.join(script_args))
                ##                print('cmd=%s' % cmd)
                return os.system(cmd)
            else:
                # If we get here, then we never found the right .py file in the
                # buildscripts component.
                print('Could not find %s.' % script)
                return 1
        else:
            print('%d sandboxes match "%s".' % (len(sandboxes), sbspec))
            return 1
    else:
        print('No sandbox matches "%s".' % sbspec)
        return 1
    return 0
Пример #5
0
def main(argv):
    # see if we're supposed to run this command against a different sandbox.
    sbspec = '.'
    del argv[0]
    if len(argv) >= 2:
        first = argv[0]
        if first == '-s':
            del argv[0]
            sbspec = argv[0]
            del argv[0]
        elif first.startswith('--sandbox') or first.startswith('--sb'):
            del argv[0]
            if '=' in first:
                sbspec = first.split('=')[1]
            else:
                sbspec = argv[0]
                del argv[0]

    # check to see if we have enough args.
    if len(argv) < 1:
        supported_verbs = _verb_to_cmd.keys()[:]
        supported_verbs.sort()
        supported_verbs = '|'.join(supported_verbs)
        supported_verbs = '(sandbox_property)|' + supported_verbs
        print('sbverb [-s <sandbox_spec>] %s [args]' % supported_verbs)
        return 1

    # Look up the script that corresponds to our verb.
    verb = argv[0].lower()
    script_args = argv[1:]
    script = _verb_to_cmd.get(verb, None)
    if not script:
        if _BZR_VERBS.match(verb):
            print('This looks like a bzr command.')
            sys.exit(1)
        if _SADM_VERBS.match(verb):
            print('This looks like a sadm command.')
            sys.exit(1)
        script = 'sandbox.py'
        script_args.insert(0, verb)

    # Now find the sandbox to which we're supposed to apply the verb.
    if sbspec == '.':
        root = sandbox.find_root_from_within(sbspec)
        if root:
            sandboxes = [sandbox.Sandbox(root)]
        else:
            print('%s is not within a sandbox.' % os.path.abspath('.'))
            return 1
    else:
        sandboxes = sadm._match_sandboxes('path', None, sbspec)
    if sandboxes:
        if len(sandboxes) == 1:
            sb = sandboxes[0]
            if verb == 'verify' and sb.get_sandboxtype().get_do_quick_build() and '--quick' not in script_args:
                script_args.append('--quick')
            if not sb.get_sandboxtype().get_do_quick_build() and '--quick' in script_args:
                script_args.remove('--quick')
            # Split cmd into script file and rest.
            i = script.find(' ')
            if i > -1:
                rest = script[i:]
                script = script[0:i]
            else:
                rest = ''

            # Now look for the appropriate buildscript .py file.
            script = os.path.join(sb.get_code_root(), 'buildscripts', script)
            if os.path.isfile(script):
                # Make sure we're using backslashes on Windows.
                if os.name == 'nt':
                    script = script.replace('/', '\\')
                # Quote if path has spaces.
                if ' ' in script:
                    script = '"%s"' % script
                script += rest
                # Re-quote any args that contain spaces
                for i in range(len(script_args)):
                    if ' ' in script_args[i] and not script_args[i].startswith('"'):
                        script_args[i] = '"%s"' % script_args[i]
                # Now run the script and report its exit code.
                cmd = 'python %s %s' % (script, ' '.join(script_args))
##                print('cmd=%s' % cmd)
                return os.system(cmd)
            else:
                # If we get here, then we never found the right .py file in the
                # buildscripts component.
                print('Could not find %s.' % script)
                return 1
        else:
            print('%d sandboxes match "%s".' % (len(sandboxes), sbspec))
            return 1
    else:
        print('No sandbox matches "%s".' % sbspec)
        return 1
    return 0