def get_review_into_file(review_url, review_file_name, target_name): utils.create_file_directories(target_name) subprocess.check_output( [ 'ash', '--no-color', review_url, 'review', review_file_name, '--output', target_name ], stderr=subprocess.STDOUT )
def _save_origin(self, source=None): entry = self.get_entry(editor.get_current_file_path()) origin_path = entry.get_origin_path() if not source and os.path.exists(origin_path): return if source is None: source = entry.get_file_path() utils.create_file_directories(origin_path) shutil.copyfile(source, origin_path)
def file_download(uuid, url, filename, expires_at): print "task executing", url print "filename", filename server_uuid=get_setting("server_uuid") file_dir = create_file_directories(uuid) print "file_dir", file_dir #uuid_filename file_path = file_dir+"/"+filename urllib.urlretrieve(url, file_path) sha256_hash = hashfile(file_path) f=File.objects.create(uuid=uuid, name=filename, file_sha256=sha256_hash) f.save() data={ "username": username, "ip_address": clientserver_ip, 'file_uuid': uuid, 'file_hash': sha256_hash, } to_hash = 'FILE_DOWNLOADED%s%s%s%s' % (data["ip_address"], data["file_uuid"], data["file_hash"], server_uuid) test_hash = hashlib.sha256(to_hash).hexdigest() print (data["ip_address"], data["file_uuid"], data["file_hash"], server_uuid) print to_hash, test_hash data['sign_key_clientserver'] = test_hash results=call_api("/clientserver/file_downloaded", urllib.urlencode(data)) print results return uuid+url
def generate_test_file(): filename="test.dat" uuid=b58encode(os.urandom(16)) file_dir = create_file_directories(uuid) file_path = file_dir+"/"+filename file_size=1024 fh = open(file_path, 'w') while os.path.getsize(file_path) <= file_size: fh.write(os.urandom(16)) fh.close() sha256_hash = hashfile(file_path) f=File.objects.create(uuid=uuid, name=filename, file_sha256=sha256_hash) f.save() set_setting("test_file", str(f.id)) pass
def create_alias(old_file, new_uuid, lifetime=None, name=None): """Create a new "copy" """ if not name: name=old_file.name expires_at=None if lifetime: expires_at=(datetime.datetime.now()+datetime.timedelta(seconds=int(lifetime))) new_file=File.objects.create(uuid=new_uuid, file_sha256=file.file_sha256, name=name, expires_at=expires_at) orig_file_path=return_file_directory(old_file.uuid)+"/"+old_file.name new_file_path=create_file_directories(new_file.uuid)+"/"+new_file.name os.symlink(orig_file_path, new_file_path) new_file.save() return new_file