Ejemplo n.º 1
0
    def create(self, python='python3', global_site_packages=False):
        # FIXME: check if python version and global_site_packages are correct,
        #        and correct / recreat (--clear?) otherwise

        if not remote.stat(self.python):
            args = [
                config['cmd_venv'],
                '-p',
                python,
            ]

            if global_site_packages:
                args.append('--system-site-packages')
            else:
                args.append('--no-site-packages')

            args.append(self.remote_path)

            proc.run(args)

            return Changed(
                msg='Initialized virtualenv in {}'.format(self.remote_path))

        return Unchanged(msg='virtualenv at {} already initialized'.format(
            self.remote_path))
Ejemplo n.º 2
0
def create_dir(path, mode=0777):
    """Ensure that a directory exists at path. Parent directories are created
    if needed.

    :param path: Directory to create if it does not exist.
    :param mode: Mode for newly created parent directories.
    :param return: ``False`` if the path existed, ``True`` otherwise.
    """
    npath = remote.path.normpath(path)

    st = remote.stat(path)

    if not st:
        head, tail = remote.path.split(path)
        if tail and head:
            # create parent directories
            create_dir(head, mode)
        remote.mkdir(npath, mode)
        return Changed(msg='Created directory: {}'.format(path))

    return Unchanged('Already exists: {}'.format(path))
Ejemplo n.º 3
0
def create_dir(path, mode=0777):
    """Ensure that a directory exists at path. Parent directories are created
    if needed.

    :param path: Directory to create if it does not exist.
    :param mode: Mode for newly created parent directories.
    :param return: ``False`` if the path existed, ``True`` otherwise.
    """
    npath = remote.path.normpath(path)

    st = remote.stat(path)

    if not st:
        head, tail = remote.path.split(path)
        if tail and head:
            # create parent directories
            create_dir(head, mode)
        remote.mkdir(npath, mode)
        return Changed(msg='Created directory: {}'.format(path))

    return Unchanged('Already exists: {}'.format(path))
Ejemplo n.º 4
0
Archivo: python.py Proyecto: mbr/remand
    def create(self, python='python3', global_site_packages=False):
        # FIXME: check if python version and global_site_packages are correct,
        #        and correct / recreat (--clear?) otherwise

        if not remote.stat(self.python):
            args = [config['cmd_venv'], '-p', python, ]

            if global_site_packages:
                args.append('--system-site-packages')
            else:
                args.append('--no-site-packages')

            args.append(self.remote_path)

            proc.run(args)

            return Changed(
                msg='Initialized virtualenv in {}'.format(self.remote_path))

        return Unchanged(msg='virtualenv at {} already initialized'.format(
            self.remote_path))
Ejemplo n.º 5
0
    def sync(self):
        log.debug('Syncing timestamp {}'.format(self.rpath))
        if self.synced:
            log.debug('Timestamp already synced')
            return

        # ensure directory for timestamp exists
        if fs.create_dir(remote.path.dirname(self.rpath), 0o755).changed:
            # had to create directory, new timestamp
            self.synced = True
            self._current = 0
            log.debug('Timestamp did not exist')
            return

        # directory already exists
        st = remote.stat(self.rpath)
        if not st:
            # file does not exist
            self._current = 0
            log.debug('Timestamp did not exist')
        else:
            self._current = st.st_mtime
            log.debug('Timestamp synced to {}'.format(self._current))
        self.synced = True
Ejemplo n.º 6
0
Archivo: apt.py Proyecto: mbr/remand
    def sync(self):
        log.debug('Syncing timestamp {}'.format(self.rpath))
        if self.synced:
            log.debug('Timestamp already synced')
            return

        # ensure directory for timestamp exists
        if fs.create_dir(remote.path.dirname(self.rpath), 0o755).changed:
            # had to create directory, new timestamp
            self.synced = True
            self._current = 0
            log.debug('Timestamp did not exist')
            return

        # directory already exists
        st = remote.stat(self.rpath)
        if not st:
            # file does not exist
            self._current = 0
            log.debug('Timestamp did not exist')
        else:
            self._current = st.st_mtime
            log.debug('Timestamp synced to {}'.format(self._current))
        self.synced = True
Ejemplo n.º 7
0
def run():
    log.warning('Running testing module. Do not run this on a real machine!')

    log.debug('Testing popen')
    proc = remote.popen(['uname'])
    stdout, stderr = proc.communicate()
    assert 'Linux' == stdout.strip()

    log.debug('Testing getcwd()')
    assert '/home/vagrant' == remote.getcwd()

    log.debug('Testing chdir()')
    remote.chdir('/')
    assert '/' == remote.getcwd()
    remote.chdir('/home/vagrant')

    # create a sample file
    TESTFN = 'testfile'
    TESTDN = 'TESTDIR'
    log.debug('Testing file')
    with remote.file(TESTFN, mode='w') as out:
        out.write('test')

    log.debug('Testing chmod')
    remote.chmod(TESTFN, 0732)

    log.debug('Testing mkdir')
    # FIXME: umask?
    # FIXME: on exists/conflict?
    remote.mkdir(TESTDN, 0700)

    log.debug('Testing listdir')
    assert TESTFN in remote.listdir('.')
    assert TESTDN in remote.listdir('.')

    log.debug('Testing rmdir')
    remote.rmdir(TESTDN)

    # FIXME: can't test chown without root access

    log.debug('Testing normalize')
    assert '/home' == remote.normalize('./..')

    log.debug('Testing symlink')
    remote.symlink('to', 'from')

    log.debug('Testing lstat')
    remote.lstat('from')

    log.debug('Testing readlink')
    assert remote.readlink('/home/vagrant/from') == 'to'

    log.debug('Testing rename')
    remote.rename('from', 'from2')
    assert remote.readlink('/home/vagrant/from2') == 'to'

    log.debug('Testing unlink')
    remote.unlink('/home/vagrant/from2')

    log.debug('Testing stat')
    s = remote.stat(TESTFN)
    assert s.st_uid == 1000
    assert s.st_gid == 1000
    remote.unlink(TESTFN)