Esempio n. 1
0
def update_from_repository(project):
    """
    Update project files from remote repository.

    Args:
        project: Project instance
    """
    log.debug("Update project files from remote repository.")

    repository_type = project.repository_type
    repository_url = project.repository_url
    repository_path = repository_path_master = \
        get_repository_path_master(project)

    # If one-locale repo, set repository_url_master and update repository_path
    repository_url_master = False
    ending = os.path.basename(os.path.normpath(repository_url))

    if ending in ('templates', 'en-US', 'en'):
        repository_url_master = repository_url.rsplit(ending, 1)[0]
        repository_path = os.path.join(repository_path_master, ending)

    # If Mozilla repo, set paths
    elif project.repository_url in MOZILLA_REPOS:
        base = 'ssh://hg.mozilla.org/releases/l10n/mozilla-'
        repository_url_master = base + ending.split("-")[-1]
        repository_path = os.path.join(repository_path_master, 'en-US')

    # Save file to server
    if repository_type == 'file':
        u = urllib2.urlopen(repository_url)
        file_name = repository_url.rstrip('/').rsplit('/', 1)[1]
        file_path = os.path.join(repository_path_master, file_name)

        if not os.path.exists(repository_path_master):
            os.makedirs(repository_path_master)

        try:
            with open(file_path, 'w') as f:
                f.write(u.read().decode("utf-8-sig").encode("utf-8"))
        except IOError as e:
            log.debug("IOError: " + str(e))

    # Save files to server
    else:
        update_from_vcs(repository_type, repository_url, repository_path)

        # If one-locale repo, also update locale repositorites
        if repository_url_master:
            for l in project.locales.all():
                update_from_vcs(
                    repository_type,
                    os.path.join(repository_url_master, l.code),
                    os.path.join(repository_path_master, l.code))

    # Store project repository_path
    project.repository_path = repository_path
    project.save()
Esempio n. 2
0
 def pull(self):
     """Pull changes from VCS."""
     if not self.multi_locale:
         update_from_vcs(self.type, self.url, self.checkout_path)
     else:
         for locale in self.project.locales.all():
             update_from_vcs(
                 self.type,
                 self.locale_url(locale),
                 self.locale_checkout_path(locale)
             )
Esempio n. 3
0
    def pull(self):
        """
        Pull changes from VCS. Returns the revision(s) of the repo after
        pulling.
        """
        if not self.multi_locale:
            update_from_vcs(self.type, self.url, self.checkout_path)
            return {
                'single_locale': get_revision(self.type, self.checkout_path)
            }
        else:
            current_revisions = {}
            for locale in self.project.locales.all():
                checkout_path = self.locale_checkout_path(locale)
                update_from_vcs(self.type, self.locale_url(locale),
                                checkout_path)
                current_revisions[locale.code] = get_revision(
                    self.type, checkout_path)

            return current_revisions
Esempio n. 4
0
    def pull(self):
        """
        Pull changes from VCS. Returns the revision(s) of the repo after
        pulling.
        """
        if not self.multi_locale:
            update_from_vcs(self.type, self.url, self.checkout_path)
            return {
                'single_locale': get_revision(self.type, self.checkout_path)
            }
        else:
            current_revisions = {}
            for locale in self.project.locales.all():
                checkout_path = self.locale_checkout_path(locale)
                update_from_vcs(
                    self.type,
                    self.locale_url(locale),
                    checkout_path
                )
                current_revisions[locale.code] = get_revision(self.type, checkout_path)

            return current_revisions
Esempio n. 5
0
def update_from_repository(project, locales=None):
    """
    Update project files from remote repository.

    Args:
        project: Project instance
        locales: List of Locale instances
    """
    log.debug("Update project files from remote repository.")

    repository_type = project.repository_type
    repository_url = project.repository_url
    repository_path = repository_path_master = \
        get_repository_path_master(project)

    # If one-locale repo, set repository_url_master and update repository_path
    repository_url_master = False
    ending = os.path.basename(os.path.normpath(repository_url))

    if ending in ('templates', 'en-US', 'en-GB', 'en'):
        repository_url_master = repository_url.rsplit(ending, 1)[0]
        repository_path = os.path.join(repository_path_master, ending)

    # Save file to server
    if repository_type == 'file':

        u = urllib2.urlopen(repository_url)
        file_name = repository_url.rstrip('/').rsplit('/', 1)[1]
        file_path = os.path.join(repository_path_master, file_name)

        if not os.path.exists(repository_path_master):
            os.makedirs(repository_path_master)

        try:
            with open(file_path, 'w') as f:
                f.write(u.read().decode("utf-8-sig").encode("utf-8"))
        except IOError as e:
            log.debug("IOError: " + str(e))

    # Save files to server
    else:

        if not locales:
            update_from_vcs(repository_type, repository_url, repository_path)

        if repository_url_master:  # One-locale repo
            if not locales:
                locales = project.locales.all()
            for l in locales:
                update_from_vcs(repository_type,
                                os.path.join(repository_url_master, l.code),
                                os.path.join(repository_path_master, l.code))

        elif locales:
            if repository_type == 'svn':
                for l in locales:
                    path = get_locale_directory(project, l)["path"]
                    update_from_vcs(repository_type, repository_url, path)

            else:
                update_from_vcs(repository_type, repository_url,
                                repository_path)

    # Store project repository_path
    project.repository_path = repository_path
    project.save()
Esempio n. 6
0
def update_from_repository(project, locales=None):
    """
    Update project files from remote repository.

    Args:
        project: Project instance
        locales: List of Locale instances
    """
    log.debug("Update project files from remote repository.")

    repository_type = project.repository_type
    repository_url = project.repository_url
    repository_path = repository_path_master = \
        get_repository_path_master(project)

    # If one-locale repo, set repository_url_master and update repository_path
    repository_url_master = False
    ending = os.path.basename(os.path.normpath(repository_url))

    if ending in ('templates', 'en-US', 'en-GB', 'en'):
        repository_url_master = repository_url.rsplit(ending, 1)[0]
        repository_path = os.path.join(repository_path_master, ending)

    # Save file to server
    if repository_type == 'file':

        u = urllib2.urlopen(repository_url)
        file_name = repository_url.rstrip('/').rsplit('/', 1)[1]
        file_path = os.path.join(repository_path_master, file_name)

        if not os.path.exists(repository_path_master):
            os.makedirs(repository_path_master)

        try:
            with open(file_path, 'w') as f:
                f.write(u.read().decode("utf-8-sig").encode("utf-8"))
        except IOError as e:
            log.debug("IOError: " + str(e))

    # Save files to server
    else:

        if not locales:
            update_from_vcs(repository_type, repository_url, repository_path)

        if repository_url_master:  # One-locale repo
            if not locales:
                locales = project.locales.all()
            for l in locales:
                update_from_vcs(
                    repository_type,
                    os.path.join(repository_url_master, l.code),
                    os.path.join(repository_path_master, l.code))

        elif locales:
            if repository_type == 'svn':
                for l in locales:
                    path = get_locale_directory(project, l)["path"]
                    update_from_vcs(repository_type, repository_url, path)

            else:
                update_from_vcs(
                    repository_type, repository_url, repository_path)

    # Store project repository_path
    project.repository_path = repository_path
    project.save()