예제 #1
0
파일: git.py 프로젝트: Simplistix/archivist
    def actions(self):
        # git init if required
        ensure_dir_exists(self.path)
        if not os.path.exists(os.path.join(self.path, '.git')):
            logger.info('creating git repo at %s', self.path)
            self.run_git('init')

        # log status
        status = self.run_git('status', '--porcelain')
        if status:
            logger.info('changes found in git repo at %s:\n%s',
                        self.path, status)

            # commit if specified
            if self.commit:
                self.run_git('add', '--all', '.')
                self.run_git('commit', '-m',
                             datetime.now().strftime(
                                 "Recorded by archivist at %Y-%m-%d %H:%M"
                             ))
                logger.info('changes committed')

            # push if specified
            if self.push:
                self.run_git('push', '-q')
                logger.info('changes pushed')
예제 #2
0
    def handle_one(self, source_path, target_path, contents):
        contents[source_path] = self.path_attributes(source_path)

        full_target, split_path = self.relative_path(source_path, target_path)
        directory = os.sep.join(split_path[:-1])

        ensure_dir_exists(directory)

        with open(source_path, 'rb') as source:
            with open(full_target, 'wb') as target:
                target.write(source.read())
예제 #3
0
파일: git.py 프로젝트: Simplistix/archivist
    def path_for(self, source):
        """
        :param source: a :class:`Source` instance.

        :return: An absolute path to a directory where sources can write.
                 This does not need to be empty and may be temporary.
        """
        parts = [self.path, source.type]
        if source.name:
            parts.append(source.name)
        full_path = os.path.join(*parts)
        ensure_dir_exists(full_path)
        return full_path
예제 #4
0
    def write_contents_file(contents, contents_path):
        ensure_dir_exists(os.path.split(contents_path)[0])
        with open(contents_path, 'w') as contents_file:
            owner_width = 0
            group_width = 0
            for perms, owner, group in contents.values():
                owner_width = max(owner_width, len(owner))
                group_width = max(group_width, len(group))

            for absolute_path, meta in sorted(contents.items()):
                perms, owner, group = meta
                contents_file.write(
                    '{perms} {owner:{owner_width}} {group:{group_width}} '
                    '{path}\n'.format(
                    perms = perms,
                    owner = owner,
                    owner_width = owner_width,
                    group = group,
                    group_width = group_width,
                    path = absolute_path,
                    ))