

def handle(self, *args, **options):
    super(Command, self).handle(*args, **options)
    self.data_dir = get_download_directory()
    (os.path.exists(self.data_dir) or os.makedirs(self.data_dir))
    self.zip_path = os.path.join(self.data_dir, self.url.split('/')[(- 1)])
    self.tsv_dir = os.path.join(self.data_dir, 'tsv/')
    download_metadata = self.get_download_metadata()
    self.current_release_datetime = download_metadata['last-modified']
    self.current_release_size = download_metadata['content-length']
    self.last_started_download = self.get_last_log()
    self.last_finished_download = self.get_last_log(finished=True)
    if self.last_finished_download:
        last_release_datetime = self.last_finished_download.version.release_datetime
        since_prev_version = naturaltime(last_release_datetime)
    else:
        last_release_datetime = None
        since_prev_version = None
    if (last_release_datetime == self.current_release_datetime):
        already_downloaded = True
    else:
        already_downloaded = False
    self.resume_download = (self.check_can_resume() and (not options['restart']))
    if self.resume_download:
        self.local_file_size = os.path.getsize(self.zip_path)
        timestamp = os.path.getmtime(self.zip_path)
        self.local_file_datetime = datetime.fromtimestamp(timestamp, utc)
    else:
        self.local_file_size = 0
        options.local_file_datetime = None
    if ((not options['noinput']) and (not options['restart'])):
        prompt_context = dict(current_release_datetime=self.current_release_datetime, resuming=self.resume_download, already_downloaded=already_downloaded, expected_size=size(self.current_release_size), local_file_size=size(self.local_file_size), download_dir=self.data_dir, since_prev_version=since_prev_version, since_local_file_modified=naturaltime(self.local_file_datetime))
        prompt = render_to_string('calaccess_raw/downloadcalaccessrawdata.txt', prompt_context)
        if (not self.confirm_proceed(prompt)):
            raise CommandError('Download cancelled')
    if self.resume_download:
        self.log_record = self.last_started_download
        self.version = self.log_record.version
    else:
        try:
            self.version = self.raw_data_versions.get(release_datetime=self.current_release_datetime)
        except RawDataVersion.DoesNotExist:
            self.version = self.raw_data_versions.create(release_datetime=self.current_release_datetime, size=download_metadata['content-length'])
        self.log_record = self.command_logs.create(version=self.version, command=self, called_by=self.get_caller_log())
    self.download()
    self.unzip()
    self.prep()
    self.track_files()
    if getattr(settings, 'CALACCESS_STORE_ARCHIVE', False):
        self.archive()
    if (not options['keep_files']):
        os.remove(self.zip_path)
        shutil.rmtree(os.path.join(self.data_dir, 'CalAccess'))
    self.log_record.finish_datetime = now()
    self.log_record.save()

dataset/ETHPy150Open california-civic-data-coalition/django-calaccess-raw-data/calaccess_raw/management/commands/downloadcalaccessrawdata.py Command.handle/VarMisuse@300/405 `self`->`options`