示例#1
0
def _scaffold_examples(directory):
    logger.debug("Copying examples tour to {}".format(directory))
    dest_dir = os.path.abspath(directory)

    # If dest_dir doesn't exist, we dump all examples in it.
    # If it does exist, we dump them into a subdirectory if it's not
    # the default dir.
    try:
        shutil.copytree(get_tourdir(), dest_dir)
    except FileExistsError:
        # default crafted directory shouldn't add itself inside
        if directory == _SNAPCRAFT_TOUR_DIR:
            raise FileExistsError("{} already exists, please specify a "
                                  "destination directory.".format(directory))
        # don't event try to copy if the dest exists already
        if not os.path.isdir(dest_dir):
            raise NotADirectoryError("{} is a file, can't be used as a "
                                     "destination".format(dest_dir))
        dest_dir = os.path.normpath(os.path.join(dest_dir,
                                                 _SNAPCRAFT_TOUR_DIR))
        shutil.copytree(get_tourdir(), dest_dir)

    print("Snapcraft tour initialized in {}\n"
          "Instructions are in the README, or "
          "http://snapcraft.io/create/#tour".format(directory))
示例#2
0
def _scaffold_examples(directory):
    logger.debug("Copying examples tour to {}".format(directory))
    dest_dir = os.path.abspath(directory)

    # If dest_dir doesn't exist, we dump all examples in it.
    # If it does exist, we dump them into a subdirectory if it's not
    # the default dir.
    try:
        shutil.copytree(get_tourdir(), dest_dir)
    except FileExistsError:
        # default crafted directory shouldn't add itself inside
        if directory == _SNAPCRAFT_TOUR_DIR:
            raise FileExistsError("{} already exists, please specify a "
                                  "destination directory.".format(directory))
        # don't event try to copy if the dest exists already
        if not os.path.isdir(dest_dir):
            raise NotADirectoryError("{} is a file, can't be used as a "
                                     "destination".format(dest_dir))
        dest_dir = os.path.normpath(os.path.join(dest_dir,
                                                 _SNAPCRAFT_TOUR_DIR))
        shutil.copytree(get_tourdir(), dest_dir)

    print("Snapcraft tour initialized in {}\n"
          "Instructions are in the README, or "
          "https://snapcraft.io/create/#begin".format(directory))
示例#3
0
def tour(directory):
    """Setup the snapcraft examples used in the tour."""
    echo.info('Copying examples tour to {}'.format(directory))
    dest_dir = os.path.abspath(directory)

    # If dest_dir doesn't exist, we dump all examples in it.
    # If it does exist, we dump them into a subdirectory if it's not
    # the default dir.
    try:
        shutil.copytree(get_tourdir(), dest_dir)
    except FileExistsError:
        # default crafted directory shouldn't add itself inside
        if directory == _SNAPCRAFT_TOUR_DIR:
            echo.error('{!r} already exists, please specify a '
                       'destination directory.'.format(directory))
            sys.exit(1)
        # don't event try to copy if the dest exists already
        if not os.path.isdir(dest_dir):
            echo.error('{!r} is a file, cannot be used as a '
                       'destination'.format(dest_dir))
            sys.exit(1)
        dest_dir = os.path.normpath(os.path.join(dest_dir,
                                                 _SNAPCRAFT_TOUR_DIR))
        shutil.copytree(get_tourdir(), dest_dir)

    click.echo('Snapcraft tour initialized in {!r}\n'
               'Instructions are in the README, or '
               'http://snapcraft.io/create/#tour'.format(directory))
示例#4
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
        self.useFixture(fixture_setup.TempXDG(self.path))
        self.fake_terminal = fixture_setup.FakeTerminal()
        self.useFixture(self.fake_terminal)
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_librariesdir, common.get_librariesdir())
        self.addCleanup(common.set_tourdir, common.get_tourdir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(os.path.join(__file__, '..', '..', '..',
                                          'schema'))
        self.useFixture(fixtures.FakeLogger(level=logging.ERROR))

        patcher = mock.patch('multiprocessing.cpu_count')
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = 2
        self.addCleanup(patcher.stop)

        patcher = mock.patch('snapcraft.internal.indicators.ProgressBar',
                             new=SilentProgressBar)
        patcher.start()
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), 'prime')
        self.stage_dir = os.path.join(os.getcwd(), 'stage')
        self.parts_dir = os.path.join(os.getcwd(), 'parts')
        self.local_plugins_dir = os.path.join(self.parts_dir, 'plugins')
示例#5
0
    def setUp(self):
        super().setUp()
        temp_cwd_fixture = fixture_setup.TempCWD()
        self.useFixture(temp_cwd_fixture)
        self.path = temp_cwd_fixture.path
        self.useFixture(fixture_setup.TempConfig(self.path))
        # Some tests will directly or indirectly change the plugindir, which
        # is a module variable. Make sure that it is returned to the original
        # value when a test ends.
        self.addCleanup(common.set_plugindir, common.get_plugindir())
        self.addCleanup(common.set_schemadir, common.get_schemadir())
        self.addCleanup(common.set_librariesdir, common.get_librariesdir())
        self.addCleanup(common.set_tourdir, common.get_tourdir())
        self.addCleanup(common.reset_env)
        common.set_schemadir(os.path.join(__file__,
                             '..', '..', '..', 'schema'))
        self.useFixture(fixtures.FakeLogger(level=logging.ERROR))

        patcher = mock.patch('multiprocessing.cpu_count')
        self.cpu_count = patcher.start()
        self.cpu_count.return_value = 2
        self.addCleanup(patcher.stop)

        # These are what we expect by default
        self.snap_dir = os.path.join(os.getcwd(), 'prime')
        self.stage_dir = os.path.join(os.getcwd(), 'stage')
        self.parts_dir = os.path.join(os.getcwd(), 'parts')
        self.local_plugins_dir = os.path.join(self.parts_dir, 'plugins')
示例#6
0
 def test_set_tourdir(self):
     tourdir = os.path.join(self.path, 'testtour')
     common.set_tourdir(tourdir)
     self.assertEqual(tourdir, common.get_tourdir())
示例#7
0
 def test_set_tourdir(self):
     tourdir = os.path.join(self.path, 'testtour')
     common.set_tourdir(tourdir)
     self.assertEqual(tourdir, common.get_tourdir())
示例#8
0
 def test_get_default_tourdir(self):
     self.assertEqual(
         '/usr/share/snapcraft/tour', common.get_tourdir())
示例#9
0
 def test_set_tourdir(self):
     self.skipTest("This test is Failing in the launchpad builders. " "Skipping while we find the reason.")
     tourdir = os.path.join(self.path, "testtour")
     common.set_tourdir(tourdir)
     self.assertEqual(tourdir, common.get_tourdir())
示例#10
0
 def test_get_default_tourdir(self):
     self.skipTest("This test is Failing in the launchpad builders. " "Skipping while we find the reason.")
     self.assertEqual("/usr/share/snapcraft/tour", common.get_tourdir())