Validates one submission and copies it to target directory.

    Args:
      submission_path: path in Google Cloud Storage of the submission file
336893
def validate_and_copy_one_submission(self, submission_path):
    
    if os.path.exists(self.download_dir):
      shutil.rmtree(self.download_dir)
    os.makedirs(self.download_dir)
    if os.path.exists(self.validate_dir):
      shutil.rmtree(self.validate_dir)
    os.makedirs(self.validate_dir)
    logging.info('\n' + ('#' * 80) + '\n# Processing submission: %s\n'
                 + '#' * 80, submission_path)
    local_path = self.copy_submission_locally(submission_path)
    metadata = self.base_validator.validate_submission(local_path)
    if not metadata:
      logging.error('Submission "%s" is INVALID', submission_path)
      self.stats.add_failure()
      return
    submission_type = metadata['type']
    container_name = metadata['container_gpu']
    logging.info('Submission "%s" is VALID', submission_path)
    self.list_of_containers.add(container_name)
    self.stats.add_success(submission_type)
    if self.do_copy:
      submission_id = '{0:04}'.format(self.cur_submission_idx)
      self.cur_submission_idx += 1
      self.copy_submission_to_destination(submission_path,
                                          TYPE_TO_DIR[submission_type],
                                          submission_id)
      self.id_to_path_mapping[submission_id] = submission_path
865746
async def put(self, path=''):
        
        self.log.info("Attempt publishing to %s", path)

        if path == '' or path == '/':
            raise web.HTTPError(400, "Must provide a path for publishing")

        model = self.get_json_body()
        if model:
            await self._publish(model, path.lstrip('/'))
        else:
            raise web.HTTPError(400, "Cannot publish an empty model")
283133
def submission_delete(self, submission_id):
        
        response = self._post(self.apiurl + '/v2/submission/delete', data={'apikey': self.apikey, 'submission_id': submission_id})

        return self._raise_or_extract(response)
152793
def main(args):
  
  print_in_box('Validating submission ' + args.submission_filename)
  random.seed()
  temp_dir = args.temp_dir
  delete_temp_dir = False
  if not temp_dir:
    temp_dir = tempfile.mkdtemp()
    logging.info('Created temporary directory: %s', temp_dir)
    delete_temp_dir = True
  validator = submission_validator_lib.SubmissionValidator(temp_dir,
                                                           args.use_gpu)
  if validator.validate_submission(args.submission_filename,
                                   args.submission_type):
    print_in_box('Submission is VALID!')
  else:
    print_in_box('Submission is INVALID, see log messages for details')
  if delete_temp_dir:
    logging.info('Deleting temporary directory: %s', temp_dir)
    subprocess.call(['rm', '-rf', temp_dir])
552947
private static Path validatePath(Path path) {
		final URI uri = path.toUri();
		final String scheme = uri.getScheme();
		final String pathPart = uri.getPath();

		// some validity checks
		if (scheme == null) {
			throw new IllegalArgumentException("The scheme (hdfs://, file://, etc) is null. " +
					"Please specify the file system scheme explicitly in the URI.");
		}
		if (pathPart == null) {
			throw new IllegalArgumentException("The path to store the checkpoint data in is null. " +
					"Please specify a directory path for the checkpoint data.");
		}
		if (pathPart.length() == 0 || pathPart.equals("/")) {
			throw new IllegalArgumentException("Cannot use the root directory for checkpoints.");
		}

		return path;
	}
997534
def upload_submit(self, upload_request):
        """"""

        path = '/api/1.0/upload/save'
        return self._api_post(definition.DatasetUploadResponse, path, upload_request)
293676
def copy(self, path):
        
        directoryPath = os.path.dirname(path)
        if not os.path.exists(directoryPath):
            os.makedirs(directoryPath)

        logger.debug('Create copy of %s in %s', os.path.basename(path), directoryPath)

        with self._snapshot() as source, _Directory(directoryPath) as dest:
            dest.SNAP_CREATE_V2(
                flags=BTRFS_SUBVOL_RDONLY,
                name=str(os.path.basename(path)),
                fd=source.fd,
            )

        with SnapShot(path) as destShot:
            flags = destShot.SUBVOL_GETFLAGS()
            destShot.SUBVOL_SETFLAGS(flags=flags.flags & ~BTRFS_SUBVOL_RDONLY)

            destShot.SET_RECEIVED_SUBVOL(
                uuid=self.received_uuid or self.uuid,
                stransid=self.sent_gen or self.current_gen,
                stime=timeOrNone(self.info.stime) or timeOrNone(self.info.ctime) or 0,
                flags=0,
            )

            destShot.SUBVOL_SETFLAGS(flags=flags.flags)
908679
private void validateOutputPath(final File path) {
        if (path.canWrite()) return;

        // If the path doesn't exist...
        if (!path.exists()) {
            // ... try creating it...
            if (!path.mkdirs()) {
                // ... or die trying.
                String err = DIRECTORY_CREATION_FAILED.concat(path.toString());
                throw new BELRuntimeException(err, UNRECOVERABLE_ERROR);
            }
            return;
        }

        // ... can't write to it.
        String err = CANT_WRITE_TO_PATH.concat(path.toString());
        throw new BELRuntimeException(err, UNRECOVERABLE_ERROR);
    }
1283348
def copy_files_from_path(path)
      UI.success("Exporting Files:")
      Dir[path].each do |f|
        existing_file = File.join(File.expand_path(Gym.config[:output_directory]), File.basename(f))
        # If the target file already exists in output directory
        # we have to remove it first, otherwise cp_r fails even with remove_destination
        # e.g.: there are symlinks in the .framework
        if File.exist?(existing_file)
          UI.important("Removing #{File.basename(f)} from output directory") if FastlaneCore::Globals.verbose?
          FileUtils.rm_rf(existing_file)
        end
        FileUtils.cp_r(f, File.expand_path(Gym.config[:output_directory]), remove_destination: true)
        UI.message("\t ▸ #{File.basename(f)}")
      end
    end
840639
def _process_submission(self, submission: praw.models.Submission):
        
        self._func_submission(submission, *self._func_submission_args)
554683
def _submit(self, pathfile, filedata, filename):
		'''
		
		'''
		if pathfile and os.path.exists(pathfile):
			files = {'file': open(pathfile, 'rb')}
		elif filedata:
			assert filename
			files = {'file' : (filename, io.BytesIO(filedata))}
		else:
			raise ValueError("You must pass either a valid file path, or a bytes array containing the captcha image!")

		payload = {
			'key'    : self.api_key,
			'method' : 'post',
			'json'   : True,
			}

		self.log.info("Uploading to 2Captcha.com.")

		url = self.getUrlFor('input', {})

		request = requests.post(url, files=files, data=payload)

		if not request.ok:
			raise exc.CaptchaSolverFailure("Posting captcha to solve failed!")

		resp_json = json.loads(request.text)
		return self._process_response(resp_json)
1048485
def run(self):
    """"""
    cmd = ['gsutil', 'ls', os.path.join(self.source_dir, '**')]
    try:
      files_list = subprocess.check_output(cmd).split('\n')
    except subprocess.CalledProcessError:
      logging.error('Can''t read source directory')
    all_submissions = [
        s for s in files_list
        if s.endswith('.zip') or s.endswith('.tar') or s.endswith('.tar.gz')
    ]
    for submission_path in all_submissions:
      self.validate_and_copy_one_submission(submission_path)
    self.stats.log_stats()
    self.save_id_to_path_mapping()
    if self.containers_file:
      with open(self.containers_file, 'w') as f:
        f.write('\n'.join(sorted(self.list_of_containers)))
500279
def copy(path, options = {}, &block)
      perform_request Net::HTTP::Copy, path, options, &block
    end
471862
def open_submission(self):
        
        url = self.get_selected_item().get('submission_permalink')
        if url:
            self.selected_page = self.open_submission_page(url)
128691
def upload_file(self, file_name, file_path):
        
        upload_key = Key(bucket=self.bucket, name=file_name)
        content_type = "text/plain"
        if file_name.endswith(".html"):
            content_type = "text/html"
        elif file_name.endswith(".jpg"):
            content_type = "image/jpeg"
        elif file_name.endswith(".png"):
            content_type = "image/png"
        upload_key.set_contents_from_filename(
            file_path,
            headers={"Content-Type": content_type})
        upload_key.url = \
            upload_key.generate_url(expires_in=3600).split("?")[0]
        try:
            upload_key.make_public()
        except Exception:
            pass
383815
def validate_zip_file_export zip_file
      path = File.dirname zip_file
      error(
        "The path to the zip file `#{path.to_path}' doesn't exist."
      )  unless (is_directory? path)
      prompt_to_replace_file zip_file  if (is_file? zip_file)
    end
768649
def copy_file_upload(self, targetdir):
        '''
            
        '''
        assert(self.file_upload)
        # unpack student data to temporary directory
        # os.chroot is not working with tarfile support
        tempdir = tempfile.mkdtemp()
        try:
            if zipfile.is_zipfile(self.file_upload.absolute_path()):
                f = zipfile.ZipFile(self.file_upload.absolute_path(), 'r')
                f.extractall(targetdir)
            elif tarfile.is_tarfile(self.file_upload.absolute_path()):
                tar = tarfile.open(self.file_upload.absolute_path())
                tar.extractall(targetdir)
                tar.close()
            else:
                # unpacking not possible, just copy it
                shutil.copyfile(self.file_upload.absolute_path(),
                                targetdir + "/" + self.file_upload.basename())
        except IOError:
            logger.error("I/O exception while accessing %s." %
                         (self.file_upload.absolute_path()))
            pass
        except (UnicodeEncodeError, NotImplementedError)  as e:
            # unpacking not possible, just copy it
            shutil.copyfile(self.file_upload.absolute_path(),
                            targetdir + "/" + self.file_upload.basename())
            pass