Exemple #1
0
def _copy_file(filename, location, link):
    copy = True
    download_location = os.path.join(location, link.filename)
    if os.path.exists(download_location):
        response = ask_path_exists(
            'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort' %
            display_path(download_location), ('i', 'w', 'b', 'a'))
        if response == 'i':
            copy = False
        elif response == 'w':
            logger.warning('Deleting %s', display_path(download_location))
            os.remove(download_location)
        elif response == 'b':
            dest_file = backup_dir(download_location)
            logger.warning(
                'Backing up %s to %s',
                display_path(download_location),
                display_path(dest_file),
            )
            shutil.move(download_location, dest_file)
        elif response == 'a':
            sys.exit(-1)
    if copy:
        shutil.copy(filename, download_location)
        logger.info('Saved %s', display_path(download_location))
def _copy_file(filename, location, link):
    copy = True
    download_location = os.path.join(location, link.filename)
    if os.path.exists(download_location):
        response = ask_path_exists(
            'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)abort' %
            display_path(download_location), ('i', 'w', 'b', 'a'))
        if response == 'i':
            copy = False
        elif response == 'w':
            logger.warning('Deleting %s', display_path(download_location))
            os.remove(download_location)
        elif response == 'b':
            dest_file = backup_dir(download_location)
            logger.warning(
                'Backing up %s to %s',
                display_path(download_location),
                display_path(dest_file),
            )
            shutil.move(download_location, dest_file)
        elif response == 'a':
            sys.exit(-1)
    if copy:
        shutil.copy(filename, download_location)
        logger.info('Saved %s', display_path(download_location))
Exemple #3
0
 def archive(self, build_dir):
     assert self.source_dir
     create_archive = True
     archive_name = '%s-%s.zip' % (self.name, self.pkg_info()["version"])
     archive_path = os.path.join(build_dir, archive_name)
     if os.path.exists(archive_path):
         response = ask_path_exists(
             'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort ' %
             display_path(archive_path), ('i', 'w', 'b', 'a'))
         if response == 'i':
             create_archive = False
         elif response == 'w':
             logger.warning('Deleting %s', display_path(archive_path))
             os.remove(archive_path)
         elif response == 'b':
             dest_file = backup_dir(archive_path)
             logger.warning(
                 'Backing up %s to %s',
                 display_path(archive_path),
                 display_path(dest_file),
             )
             shutil.move(archive_path, dest_file)
         elif response == 'a':
             sys.exit(-1)
     if create_archive:
         zip = zipfile.ZipFile(archive_path,
                               'w',
                               zipfile.ZIP_DEFLATED,
                               allowZip64=True)
         dir = os.path.normcase(os.path.abspath(self.setup_py_dir))
         for dirpath, dirnames, filenames in os.walk(dir):
             if 'pip-egg-info' in dirnames:
                 dirnames.remove('pip-egg-info')
             for dirname in dirnames:
                 dirname = os.path.join(dirpath, dirname)
                 name = self._clean_zip_name(dirname, dir)
                 zipdir = zipfile.ZipInfo(self.name + '/' + name + '/')
                 zipdir.external_attr = 0x1ED << 16  # 0o755
                 zip.writestr(zipdir, '')
             for filename in filenames:
                 if filename == PIP_DELETE_MARKER_FILENAME:
                     continue
                 filename = os.path.join(dirpath, filename)
                 name = self._clean_zip_name(filename, dir)
                 zip.write(filename, self.name + '/' + name)
         zip.close()
         logger.info('Saved %s', display_path(archive_path))
Exemple #4
0
 def archive(self, build_dir):
     assert self.source_dir
     create_archive = True
     archive_name = '%s-%s.zip' % (self.name, self.pkg_info()["version"])
     archive_path = os.path.join(build_dir, archive_name)
     if os.path.exists(archive_path):
         response = ask_path_exists(
             'The file %s exists. (i)gnore, (w)ipe, (b)ackup, (a)bort ' %
             display_path(archive_path), ('i', 'w', 'b', 'a'))
         if response == 'i':
             create_archive = False
         elif response == 'w':
             logger.warning('Deleting %s', display_path(archive_path))
             os.remove(archive_path)
         elif response == 'b':
             dest_file = backup_dir(archive_path)
             logger.warning(
                 'Backing up %s to %s',
                 display_path(archive_path),
                 display_path(dest_file),
             )
             shutil.move(archive_path, dest_file)
         elif response == 'a':
             sys.exit(-1)
     if create_archive:
         zip = zipfile.ZipFile(
             archive_path, 'w', zipfile.ZIP_DEFLATED,
             allowZip64=True
         )
         dir = os.path.normcase(os.path.abspath(self.setup_py_dir))
         for dirpath, dirnames, filenames in os.walk(dir):
             if 'pip-egg-info' in dirnames:
                 dirnames.remove('pip-egg-info')
             for dirname in dirnames:
                 dirname = os.path.join(dirpath, dirname)
                 name = self._clean_zip_name(dirname, dir)
                 zipdir = zipfile.ZipInfo(self.name + '/' + name + '/')
                 zipdir.external_attr = 0x1ED << 16  # 0o755
                 zip.writestr(zipdir, '')
             for filename in filenames:
                 if filename == PIP_DELETE_MARKER_FILENAME:
                     continue
                 filename = os.path.join(dirpath, filename)
                 name = self._clean_zip_name(filename, dir)
                 zip.write(filename, self.name + '/' + name)
         zip.close()
         logger.info('Saved %s', display_path(archive_path))
Exemple #5
0
    def check_destination(self, dest, url, rev_options, rev_display):
        """
        Prepare a location to receive a checkout/clone.

        Return True if the location is ready for (and requires) a
        checkout/clone, False otherwise.
        """
        checkout = True
        prompt = False
        if os.path.exists(dest):
            checkout = False
            if os.path.exists(os.path.join(dest, self.dirname)):
                existing_url = self.get_url(dest)
                if self.compare_urls(existing_url, url):
                    logger.debug(
                        "%s in %s exists, and has correct URL (%s)", self.repo_name.title(), display_path(dest), url
                    )
                    logger.info("Updating %s %s%s", display_path(dest), self.repo_name, rev_display)
                    self.update(dest, rev_options)
                else:
                    logger.warning(
                        "%s %s in %s exists with URL %s", self.name, self.repo_name, display_path(dest), existing_url
                    )
                    prompt = ("(s)witch, (i)gnore, (w)ipe, (b)ackup ", ("s", "i", "w", "b"))
            else:
                logger.warning("Directory %s already exists, and is not a %s %s.", dest, self.name, self.repo_name)
                prompt = ("(i)gnore, (w)ipe, (b)ackup ", ("i", "w", "b"))
        if prompt:
            logger.warning("The plan is to install the %s repository %s", self.name, url)
            response = ask_path_exists("What to do?  %s" % prompt[0], prompt[1])

            if response == "s":
                logger.info("Switching %s %s to %s%s", self.repo_name, display_path(dest), url, rev_display)
                self.switch(dest, url, rev_options)
            elif response == "i":
                # do nothing
                pass
            elif response == "w":
                logger.warning("Deleting %s", display_path(dest))
                rmtree(dest)
                checkout = True
            elif response == "b":
                dest_dir = backup_dir(dest)
                logger.warning("Backing up %s to %s", display_path(dest), dest_dir)
                shutil.move(dest, dest_dir)
                checkout = True
        return checkout
Exemple #6
0
def _copy_file(filename, location, content_type, link):
    copy = True
    download_location = os.path.join(location, link.filename)
    if os.path.exists(download_location):
        response = ask_path_exists(
            "The file %s exists. (i)gnore, (w)ipe, (b)ackup " % display_path(download_location), ("i", "w", "b")
        )
        if response == "i":
            copy = False
        elif response == "w":
            logger.warning("Deleting %s", display_path(download_location))
            os.remove(download_location)
        elif response == "b":
            dest_file = backup_dir(download_location)
            logger.warning("Backing up %s to %s", display_path(download_location), display_path(dest_file))
            shutil.move(download_location, dest_file)
    if copy:
        shutil.copy(filename, download_location)
        logger.info("Saved %s", display_path(download_location))
 def archive(self, build_dir):
     assert self.source_dir
     create_archive = True
     archive_name = "%s-%s.zip" % (self.name, self.pkg_info()["version"])
     archive_path = os.path.join(build_dir, archive_name)
     if os.path.exists(archive_path):
         response = ask_path_exists(
             "The file %s exists. (i)gnore, (w)ipe, (b)ackup " % display_path(archive_path), ("i", "w", "b")
         )
         if response == "i":
             create_archive = False
         elif response == "w":
             logger.warning("Deleting %s", display_path(archive_path))
             os.remove(archive_path)
         elif response == "b":
             dest_file = backup_dir(archive_path)
             logger.warning("Backing up %s to %s", display_path(archive_path), display_path(dest_file))
             shutil.move(archive_path, dest_file)
     if create_archive:
         zip = zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED, allowZip64=True)
         dir = os.path.normcase(os.path.abspath(self.source_dir))
         for dirpath, dirnames, filenames in os.walk(dir):
             if "pip-egg-info" in dirnames:
                 dirnames.remove("pip-egg-info")
             for dirname in dirnames:
                 dirname = os.path.join(dirpath, dirname)
                 name = self._clean_zip_name(dirname, dir)
                 zipdir = zipfile.ZipInfo(self.name + "/" + name + "/")
                 zipdir.external_attr = 0x1ED << 16  # 0o755
                 zip.writestr(zipdir, "")
             for filename in filenames:
                 if filename == PIP_DELETE_MARKER_FILENAME:
                     continue
                 filename = os.path.join(dirpath, filename)
                 name = self._clean_zip_name(filename, dir)
                 zip.write(filename, self.name + "/" + name)
         zip.close()
         logger.info("Saved %s", display_path(archive_path))
Exemple #8
0
    def check_destination(self, dest, url, rev_options, rev_display):
        """
        Prepare a location to receive a checkout/clone.

        Return True if the location is ready for (and requires) a
        checkout/clone, False otherwise.
        """
        checkout = True
        prompt = False
        if os.path.exists(dest):
            checkout = False
            if os.path.exists(os.path.join(dest, self.dirname)):
                existing_url = self.get_url(dest)
                if self.compare_urls(existing_url, url):
                    logger.debug(
                        '%s in %s exists, and has correct URL (%s)',
                        self.repo_name.title(),
                        display_path(dest),
                        url,
                    )
                    if not self.check_version(dest, rev_options):
                        logger.info(
                            'Updating %s %s%s',
                            display_path(dest),
                            self.repo_name,
                            rev_display,
                        )
                        self.update(dest, rev_options)
                    else:
                        logger.info('Skipping because already up-to-date.')
                else:
                    logger.warning(
                        '%s %s in %s exists with URL %s',
                        self.name,
                        self.repo_name,
                        display_path(dest),
                        existing_url,
                    )
                    prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ',
                              ('s', 'i', 'w', 'b'))
            else:
                logger.warning(
                    'Directory %s already exists, and is not a %s %s.',
                    dest,
                    self.name,
                    self.repo_name,
                )
                prompt = ('(i)gnore, (w)ipe, (b)ackup ', ('i', 'w', 'b'))
        if prompt:
            logger.warning(
                'The plan is to install the %s repository %s',
                self.name,
                url,
            )
            response = ask_path_exists('What to do?  %s' % prompt[0],
                                       prompt[1])

            if response == 's':
                logger.info(
                    'Switching %s %s to %s%s',
                    self.repo_name,
                    display_path(dest),
                    url,
                    rev_display,
                )
                self.switch(dest, url, rev_options)
            elif response == 'i':
                # do nothing
                pass
            elif response == 'w':
                logger.warning('Deleting %s', display_path(dest))
                rmtree(dest)
                checkout = True
            elif response == 'b':
                dest_dir = backup_dir(dest)
                logger.warning(
                    'Backing up %s to %s',
                    display_path(dest),
                    dest_dir,
                )
                shutil.move(dest, dest_dir)
                checkout = True
            elif response == 'a':
                sys.exit(-1)
        return checkout
Exemple #9
0
    def check_destination(self, dest, url, rev_options, rev_display):
        """
        Prepare a location to receive a checkout/clone.

        Return True if the location is ready for (and requires) a
        checkout/clone, False otherwise.
        """
        checkout = True
        prompt = False
        if os.path.exists(dest):
            checkout = False
            if os.path.exists(os.path.join(dest, self.dirname)):
                existing_url = self.get_url(dest)
                if self.compare_urls(existing_url, url):
                    logger.debug(
                        '%s in %s exists, and has correct URL (%s)',
                        self.repo_name.title(),
                        display_path(dest),
                        url,
                    )
                    if not self.check_version(dest, rev_options):
                        logger.info(
                            'Updating %s %s%s',
                            display_path(dest),
                            self.repo_name,
                            rev_display,
                        )
                        self.update(dest, rev_options)
                    else:
                        logger.info(
                            'Skipping because already up-to-date.')
                else:
                    logger.warning(
                        '%s %s in %s exists with URL %s',
                        self.name,
                        self.repo_name,
                        display_path(dest),
                        existing_url,
                    )
                    prompt = ('(s)witch, (i)gnore, (w)ipe, (b)ackup ',
                              ('s', 'i', 'w', 'b'))
            else:
                logger.warning(
                    'Directory %s already exists, and is not a %s %s.',
                    dest,
                    self.name,
                    self.repo_name,
                )
                prompt = ('(i)gnore, (w)ipe, (b)ackup ', ('i', 'w', 'b'))
        if prompt:
            logger.warning(
                'The plan is to install the %s repository %s',
                self.name,
                url,
            )
            response = ask_path_exists('What to do?  %s' % prompt[0],
                                       prompt[1])

            if response == 's':
                logger.info(
                    'Switching %s %s to %s%s',
                    self.repo_name,
                    display_path(dest),
                    url,
                    rev_display,
                )
                self.switch(dest, url, rev_options)
            elif response == 'i':
                # do nothing
                pass
            elif response == 'w':
                logger.warning('Deleting %s', display_path(dest))
                rmtree(dest)
                checkout = True
            elif response == 'b':
                dest_dir = backup_dir(dest)
                logger.warning(
                    'Backing up %s to %s', display_path(dest), dest_dir,
                )
                shutil.move(dest, dest_dir)
                checkout = True
        return checkout