Example #1
0
def commit():
    """git commit source changes from all tracked files

    include:

      - add all tracked files in the work tree, include modified(M), deleted(D)
      - commit all files in the index, include added(A), modified(M),
        renamed(R), deleted(D)
      - untracked files should be manually added to the index before
        run this task

    before do commit, it requires to confirm the files to be committed; and
    the requirement before do add is a future feature, it is currently
    disabled.
    """
    message = 'Update Documentation'
    yes_ans = ('y', 'yes')

    with settings(warn_only=True):
        # Changes in the work tree to add
        add_file = '--update .'  # include tracked files
        # hack of res.return_code without warning info
        res = local('git diff --quiet --exit-code; echo $?', capture=True)
        if int(res.strip()):
            if False:  # future feature?
                # TODO: there use diff to uniform with below, and the
                # output can be formatted like `git add --dry-run --update .`
                test_res = local('git diff --name-status', capture=True)
                try:
                    _ans = raw_input(
                        '\n{0}\nAdd these files to index? (y/N) '.format(
                            test_res.strip()))
                    if _ans.lower() in yes_ans:
                        local('git add {0}'.format(add_file))
                except (KeyboardInterrupt, SystemExit):
                    pass
            else:
                local('git add {0}'.format(add_file))

        # Changes in the index to commit
        res = local('git diff --cached --quiet --exit-code; echo $?',
                    capture=True)
        if int(res.strip()):
            test_res = local('git diff --cached --name-status', capture=True)
            try:
                _ans = raw_input('\n{0}\nCommit these files? (y/N) '.format(
                    test_res.strip()))
                if _ans.lower() in yes_ans:
                    local("git commit -m '{0}'".format(message))
            except (KeyboardInterrupt, SystemExit):
                pass
        else:
            print('Nothing to commit.')
Example #2
0
def commit():
    """git commit source changes from all tracked files

    include:

      - add all tracked files in the work tree, include modified(M), deleted(D)
      - commit all files in the index, include added(A), modified(M),
        renamed(R), deleted(D)
      - untracked files should be manually added to the index before
        run this task

    before do commit, it requires to confirm the files to be committed; and
    the requirement before do add is a future feature, it is currently
    disabled.
    """
    message = 'Update Documentation'
    yes_ans = ('y', 'yes')

    with settings(warn_only=True):
        # Changes in the work tree to add
        add_file = '--update .'  # include tracked files
        # hack of res.return_code without warning info
        res = local('git diff --quiet --exit-code; echo $?', capture=True)
        if int(res.strip()):
            if False:  # future feature?
                # TODO: there use diff to uniform with below, and the
                # output can be formatted like `git add --dry-run --update .`
                test_res = local('git diff --name-status', capture=True)
                try:
                    _ans = raw_input('\n{0}\nAdd these files to index? (y/N) '
                                     .format(test_res.strip()))
                    if _ans.lower() in yes_ans:
                        local("git add {0}".format(add_file))
                except (KeyboardInterrupt, SystemExit):
                    pass
            else:
                local("git add {0}".format(add_file))

        # Changes in the index to commit
        res = local('git diff --cached --quiet --exit-code; echo $?',
                    capture=True)
        if int(res.strip()):
            test_res = local('git diff --cached --name-status', capture=True)
            try:
                _ans = raw_input('\n{0}\nCommit these files? (y/N) '
                                 .format(test_res.strip()))
                if _ans.lower() in yes_ans:
                    local("git commit -m '{0}'".format(message))
            except (KeyboardInterrupt, SystemExit):
                pass
        else:
            print('Nothing to commit.')
Example #3
0
    def init(self, ask=False, **kwargs):
        content_path = os.path.join(self.target_path, self.config["source"])
        output_path = os.path.join(self.target_path,
                                   self.config["destination"])
        theme_path = os.path.join(self.target_path, self.config['themes_dir'])
        for path in (content_path, output_path, theme_path):
            if os.path.exists(path):
                logging.warning("{0} exists".format(path))
            else:
                mkdir_p(path)
                logging.info("Creating directory: {0}".format(path))

        self.get_config_file()
        self.get_fabfile()
        self.get_demo_page()
        self.get_default_theme(theme_path)

        if ask is True:
            try:
                _ans = raw_input('Create Dockerfile? (y/N) ')
                if _ans.lower() in yes_answer:
                    self.get_dockerfile()
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
        elif ask is False and kwargs.get('dockerfile', False):
            self.get_dockerfile()
Example #4
0
def get_input(text):
    return raw_input(text)
Example #5
0
def get_input(text):
    return raw_input(text)
Example #6
0
def update_builtin():
    '''Update builtin scripts and themes under local site'''
    # for fabfile.py
    yes_ans = ('y', 'yes')
    _fabfile_r = os.path.join(os.path.dirname(__file__), 'conf_templates',
                              'fabfile.py')
    _fabfile_l = os.path.join(os.getcwd(), 'fabfile.py')
    if os.path.exists(_fabfile_l):
        # py3 require md5 with bytes object, otherwise raise
        # TypeError: Unicode-objects must be encoded before hashing
        with open(_fabfile_r, 'rb') as _fd:
            _fabfile_r_md5 = hashlib.md5(_fd.read()).hexdigest()
        with open(_fabfile_l, 'rb') as _fd:
            _fabfile_l_md5 = hashlib.md5(_fd.read()).hexdigest()
        if _fabfile_l_md5 != _fabfile_r_md5:
            try:
                _ans = raw_input('Overwrite fabfile.py? (y/N) ')
                if _ans.lower() in yes_ans:
                    shutil.copy2(_fabfile_r, _fabfile_l)
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
    else:
        try:
            _ans = raw_input('New fabfile.py? (y/N) ')
            if _ans.lower() in yes_ans:
                shutil.copy2(_fabfile_r, _fabfile_l)
        except (KeyboardInterrupt, SystemExit):
            print()

    # for themes
    _themes_r = os.path.join(os.path.dirname(__file__), 'themes')
    _themes_l = os.path.join(os.getcwd(), config['themes_dir'])
    for theme in os.listdir(_themes_r):
        _theme_r = os.path.join(_themes_r, theme)
        _theme_l = os.path.join(_themes_l, theme)
        if os.path.exists(_theme_l):
            _need_update = False
            for root, dirs, files in os.walk(_theme_r):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                for filename in files:
                    with open(os.path.join(root, filename), 'rb') as _fd:
                        _theme_r_md5 = hashlib.md5(_fd.read()).hexdigest()
                    _dir = os.path.relpath(root, _theme_r)
                    with open(os.path.join(_theme_l, _dir, filename),
                              'rb') as _fd:
                        _theme_l_md5 = hashlib.md5(_fd.read()).hexdigest()
                    if _theme_l_md5 != _theme_r_md5:
                        _need_update = True
                        break
                if _need_update:
                    break
            if _need_update:
                try:
                    _ans = raw_input(
                        'Overwrite theme {0}? (y/N) '.format(theme))
                    if _ans.lower() in yes_ans:
                        shutil.rmtree(_theme_l)
                        copytree(_theme_r, _theme_l)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            try:
                _ans = raw_input('New theme {0}? (y/N) '.format(theme))
                if _ans.lower() in yes_ans:
                    copytree(_theme_r, _theme_l)
            except (KeyboardInterrupt, SystemExit):
                print()
Example #7
0
def update_builtin():
    '''Update builtin scripts and themes under local site'''
    # for fabfile.py
    yes_ans = ('y', 'yes')
    _fabfile_r = os.path.join(os.path.dirname(__file__), 'conf_templates',
                              'fabfile.py')
    _fabfile_l = os.path.join(os.getcwd(), 'fabfile.py')
    if os.path.exists(_fabfile_l):
        # py3 require md5 with bytes object, otherwise raise
        # TypeError: Unicode-objects must be encoded before hashing
        with open(_fabfile_r, 'rb') as _fd:
            _fabfile_r_md5 = hashlib.md5(_fd.read()).hexdigest()
        with open(_fabfile_l, 'rb') as _fd:
            _fabfile_l_md5 = hashlib.md5(_fd.read()).hexdigest()
        if _fabfile_l_md5 != _fabfile_r_md5:
            try:
                _ans = raw_input('Overwrite fabfile.py? (y/N) ')
                if _ans.lower() in yes_ans:
                    shutil.copy2(_fabfile_r, _fabfile_l)
            except (KeyboardInterrupt, SystemExit):
                print()  # newline with Ctrl-C
    else:
        try:
            _ans = raw_input('New fabfile.py? (y/N) ')
            if _ans.lower() in yes_ans:
                shutil.copy2(_fabfile_r, _fabfile_l)
        except (KeyboardInterrupt, SystemExit):
            print()

    # for themes
    _themes_r = os.path.join(os.path.dirname(__file__), 'themes')
    _themes_l = os.path.join(os.getcwd(), config['themes_dir'])
    for theme in os.listdir(_themes_r):
        _theme_r = os.path.join(_themes_r, theme)
        _theme_l = os.path.join(_themes_l, theme)
        if os.path.exists(_theme_l):
            _need_update = False
            for root, dirs, files in os.walk(_theme_r):
                files = [f for f in files if not f.startswith(".")]
                dirs[:] = [d for d in dirs if not d.startswith(".")]
                for filename in files:
                    with open(os.path.join(root, filename), 'rb') as _fd:
                        _theme_r_md5 = hashlib.md5(_fd.read()).hexdigest()
                    _dir = os.path.relpath(root, _theme_r)
                    with open(os.path.join(_theme_l, _dir, filename),
                              'rb') as _fd:
                        _theme_l_md5 = hashlib.md5(_fd.read()).hexdigest()
                    if _theme_l_md5 != _theme_r_md5:
                        _need_update = True
                        break
                if _need_update:
                    break
            if _need_update:
                try:
                    _ans = raw_input('Overwrite theme {0}? (y/N) '
                                     .format(theme))
                    if _ans.lower() in yes_ans:
                        shutil.rmtree(_theme_l)
                        copytree(_theme_r, _theme_l)
                except (KeyboardInterrupt, SystemExit):
                    print()
        else:
            try:
                _ans = raw_input('New theme {0}? (y/N) '.format(theme))
                if _ans.lower() in yes_ans:
                    copytree(_theme_r, _theme_l)
            except (KeyboardInterrupt, SystemExit):
                print()