コード例 #1
0
 def assert_writestr(path, contents, *entries):
   with self.jarfile() as jarfile:
     with open_jar(jarfile, 'w') as jar:
       jar.writestr(path, contents)
     with open_jar(jarfile) as jar:
       self.assertEquals(list(entries), jar.namelist())
       self.assertEquals(contents, jar.read(path))
コード例 #2
0
 def test_write_dir(self):
   with temporary_dir() as chroot:
     dir = os.path.join(chroot, 'a/b/c')
     safe_mkdir(dir)
     with self.jarfile() as jarfile:
       with open_jar(jarfile, 'w') as jar:
         jar.write(dir, 'd/e')
       with open_jar(jarfile) as jar:
         self.assertEquals(['d/', 'd/e/'], jar.namelist())
コード例 #3
0
 def test_write_file(self):
   with temporary_dir() as chroot:
     dir = os.path.join(chroot, 'a/b/c')
     safe_mkdir(dir)
     data_file = os.path.join(dir, 'd.txt')
     with open(data_file, 'w') as fd:
       fd.write('e')
     with self.jarfile() as jarfile:
       with open_jar(jarfile, 'w') as jar:
         jar.write(data_file, 'f/g/h')
       with open_jar(jarfile) as jar:
         self.assertEquals(['f/', 'f/g/', 'f/g/h'], jar.namelist())
         self.assertEquals('e', jar.read('f/g/h'))
コード例 #4
0
ファイル: binary_create.py プロジェクト: BabyDuncan/commons
  def create_binary(self, binary):
    import platform
    safe_mkdir(self.outdir)

    jarmap = self.context.products.get('jars')

    binary_jarname = '%s.jar' % binary.basename
    binaryjarpath = os.path.join(self.outdir, binary_jarname)
    self.context.log.info('creating %s' % os.path.relpath(binaryjarpath, get_buildroot()))

    with open_jar(binaryjarpath, 'w', compression=self.compression, allowZip64=self.zip64) as jar:
      def add_jars(target):
        generated = jarmap.get(target)
        if generated:
          for basedir, jars in generated.items():
            for internaljar in jars:
              self.dump(os.path.join(basedir, internaljar), jar)

      binary.walk(add_jars, is_internal)

      if self.deployjar:
        for basedir, externaljar in self.list_jar_dependencies(binary):
          self.dump(os.path.join(basedir, externaljar), jar)

      manifest = Manifest()
      manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
      manifest.addentry(
        Manifest.CREATED_BY,
        'python %s pants %s (Twitter, Inc.)' % (platform.python_version(), get_version())
      )
      main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***'
      manifest.addentry(Manifest.MAIN_CLASS,  main)
      jar.writestr(Manifest.PATH, manifest.contents())

      jarmap.add(binary, self.outdir, [binary_jarname])
コード例 #5
0
ファイル: jar_create.py プロジェクト: alfss/commons
 def create_jar(self, target, path):
   existing = self._jars.setdefault(path, target)
   if target != existing:
     raise TaskError('Duplicate name: target %s tried to write %s already mapped to target %s' % (
       target, path, existing
     ))
   self._jars[path] = target
   with open_jar(path, 'w', compression=self.compression) as jar:
     yield jar
コード例 #6
0
 def create_jar(self, target, path):
   existing = self._jars.setdefault(path, target)
   if target != existing:
     raise TaskError('Duplicate name: target %s tried to write %s already mapped to target %s' % (
       target, path, existing
     ))
   self._jars[path] = target
   with open_jar(path, 'w', compression=self.compression) as jar:
     yield jar
コード例 #7
0
ファイル: binary_create.py プロジェクト: xianxu/pants
    def create_binary(self, binary):
        import platform
        safe_mkdir(self.outdir)

        jarmap = self.context.products.get('jars')

        binary_jarname = '%s.jar' % binary.basename
        binaryjarpath = os.path.join(self.outdir, binary_jarname)
        self.context.log.info('creating %s' %
                              os.path.relpath(binaryjarpath, get_buildroot()))

        with open_jar(binaryjarpath,
                      'w',
                      compression=self.compression,
                      allowZip64=self.zip64) as jar:

            def add_jars(target):
                generated = jarmap.get(target)
                if generated:
                    for basedir, jars in generated.items():
                        for internaljar in jars:
                            self.dump(os.path.join(basedir, internaljar), jar)

            binary.walk(add_jars, is_internal)

            if self.deployjar:
                for basedir, externaljar in self.list_jar_dependencies(binary):
                    self.dump(os.path.join(basedir, externaljar), jar)

            manifest = Manifest()
            manifest.addentry(Manifest.MANIFEST_VERSION, '1.0')
            manifest.addentry(
                Manifest.CREATED_BY, 'python %s pants %s (Twitter, Inc.)' %
                (platform.python_version(), get_version()))
            main = binary.main or '*** java -jar not supported, please use -cp and pick a main ***'
            manifest.addentry(Manifest.MAIN_CLASS, main)
            jar.writestr(Manifest.PATH, manifest.contents())

            jarmap.add(binary, self.outdir, [binary_jarname])
コード例 #8
0
 def assert_mkdirs(path, *entries):
   with self.jarfile() as jarfile:
     with open_jar(jarfile, 'w') as jar:
       jar.mkdirs(path)
     with open_jar(jarfile) as jar:
       self.assertEquals(list(entries), jar.namelist())