Ejemplo n.º 1
0
    def handle(self, *args, **options):
        vcs_type = options['vcs_type']
        vcs_address = args[0]
        sync_fields = ('name', 'version', 'build', 'release', 'summary')

        if vcs_type == 'subversion':
            yaml = get_yaml_from_subversion(vcs_address)
            vcs_type = VCS_SUBVERSION
        elif vcs_type == 'mercurial':
            yaml = get_yaml_from_mercurial(vcs_address)
            vcs_type = VCS_MERCURIAL
        elif vcs_type == 'git':
            yaml = get_yaml_from_git(vcs_address)
            vcs_type = VCS_GIT
        else:
            raise Exception('unknown vcs_type')

        # set non-exist key to blank
        map(lambda x: yaml['default'].setdefault(x, ''), sync_fields)
        package_args = dict(map(lambda x: (x, yaml['default'][x]),
                                sync_fields))
        package = Package(**package_args)
        package.owner = User.objects.get(username=options['user'])
        package.vcs_type = vcs_type
        package.vcs_address = vcs_address
        package.save()
Ejemplo n.º 2
0
    def clean(self):
        super(PackageCreateForm, self).clean()

        cleaned_data = self.cleaned_data

        if not VCS_BASE_RE.match(cleaned_data['vcs_address']):
            raise forms.ValidationError(_('invalid base address'))

        try:
            if cleaned_data['vcs_type'] == VCS_SUBVERSION:
                yaml = get_yaml_from_subversion(cleaned_data['vcs_address'],
                                                cleaned_data['vcs_subdir'])
            elif cleaned_data['vcs_type'] == VCS_MERCURIAL:
                yaml = get_yaml_from_mercurial(cleaned_data['vcs_address'],
                                               cleaned_data['vcs_subdir'])
            elif cleaned_data['vcs_type'] == VCS_GIT:
                yaml = get_yaml_from_git(cleaned_data['vcs_address'],
                                         cleaned_data['vcs_subdir'])
        except ComposerError as e:
            raise forms.ValidationError(_('syntax errors in index.yaml'))
        except IndexNotFoundError as e:
            raise forms.ValidationError(e)
        except RemotePackageNotFoundError as e:
            raise forms.ValidationError(_('"%s" does not exists')
                                        % e.message)
        except:
            raise

        # set non-exist key to blank
        map(lambda x: yaml['default'].setdefault(x, ''), self.default_fields)
        map(lambda x: cleaned_data.update({x: yaml['default'][x]}),
            self.default_fields)

        cleaned_data['.'] = yaml['.']
        pkgname = yaml['default']['name']

        try:
            package = Package.objects.get(name=pkgname)
            if package.owner != self.user:
                msg = _('Package "%s" already exists and '
                        'it is not owned by you' % pkgname)
                raise forms.ValidationError(msg)
            self.exist = package
        except Package.DoesNotExist:
            pass

        return cleaned_data
Ejemplo n.º 3
0
def sync_view(request, pk):
    from multipkg.models import VCS_SUBVERSION, VCS_MERCURIAL, VCS_GIT
    from multipkg.utils import get_yaml_from_subversion
    from multipkg.utils import get_yaml_from_mercurial
    from multipkg.utils import get_yaml_from_git
    from multipkg.forms import PackageCreateForm

    default_fields = PackageCreateForm.default_fields

    try:
        package = Package.objects.get(pk=pk)
        if package.vcs_type == VCS_SUBVERSION:
            yaml = get_yaml_from_subversion(package.vcs_address,
                                            package.vcs_subdir)
        elif package.vcs_type == VCS_MERCURIAL:
            yaml = get_yaml_from_mercurial(package.vcs_address,
                                           package.vcs_subdir)
        elif package.vcs_type == VCS_GIT:
            yaml = get_yaml_from_git(package.vcs_address, package.vcs_subdir)

        default = yaml['default']
        map(lambda x: yaml['default'].setdefault(x, ''), default_fields)

        if package.name != default['name']:
            raise PackageNameInconsistentError()

        package.name = default['name']
        package.version = default['version']
        package.build = default['build']
        package.release = default['release']
        package.summary = default['summary']

        package.recent_changes = yaml['.']['recent_changes']

        package.save()
        return HttpResponse('Package %s refreshed sucessfully' % package.name)
    except Package.DoesNotExist:
        return HttpResponse('NOTEXIST')