Python os.mknod() Examples
The following are 30
code examples of os.mknod().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_posix.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_mknod(self): # Test using mknod() to create a FIFO (the only use specified # by POSIX). support.unlink(support.TESTFN) mode = stat.S_IFIFO | stat.S_IRUSR | stat.S_IWUSR try: posix.mknod(support.TESTFN, mode, 0) except OSError as e: # Some old systems don't allow unprivileged users to use # mknod(), or only support creating device nodes. self.assertIn(e.errno, (errno.EPERM, errno.EINVAL)) else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) # Keyword arguments are also supported support.unlink(support.TESTFN) try: posix.mknod(path=support.TESTFN, mode=mode, device=0, dir_fd=None) except OSError as e: self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
Example #2
Source File: test_posix.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_mknod(self): # Test using mknod() to create a FIFO (the only use specified # by POSIX). support.unlink(support.TESTFN) mode = stat.S_IFIFO | stat.S_IRUSR | stat.S_IWUSR try: posix.mknod(support.TESTFN, mode, 0) except OSError as e: # Some old systems don't allow unprivileged users to use # mknod(), or only support creating device nodes. self.assertIn(e.errno, (errno.EPERM, errno.EINVAL)) else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) # Keyword arguments are also supported support.unlink(support.TESTFN) try: posix.mknod(path=support.TESTFN, mode=mode, device=0, dir_fd=None) except OSError as e: self.assertIn(e.errno, (errno.EPERM, errno.EINVAL))
Example #3
Source File: test_posix.py From ironpython3 with Apache License 2.0 | 6 votes |
def test_mknod_dir_fd(self): # Test using mknodat() to create a FIFO (the only use specified # by POSIX). support.unlink(support.TESTFN) mode = stat.S_IFIFO | stat.S_IRUSR | stat.S_IWUSR f = posix.open(posix.getcwd(), posix.O_RDONLY) try: posix.mknod(support.TESTFN, mode, 0, dir_fd=f) except OSError as e: # Some old systems don't allow unprivileged users to use # mknod(), or only support creating device nodes. self.assertIn(e.errno, (errno.EPERM, errno.EINVAL)) else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) finally: posix.close(f)
Example #4
Source File: tom_setup.py From tom_base with GNU General Public License v3.0 | 6 votes |
def create_project_dirs(self): self.status('Creating project directories... ') try: os.mkdir(os.path.join(BASE_DIR, 'data')) except FileExistsError: pass try: os.mkdir(os.path.join(BASE_DIR, 'templates')) except FileExistsError: pass try: os.mkdir(os.path.join(BASE_DIR, 'static')) except FileExistsError: pass # os.mknod requires superuser permissions on osx, so create a blank file instead try: open(os.path.join(BASE_DIR, 'static/.keep'), 'w').close() except FileExistsError: pass try: os.mkdir(os.path.join(BASE_DIR, 'tmp')) except FileExistsError: pass self.ok()
Example #5
Source File: binary_extractor_test.py From turbinia with Apache License 2.0 | 6 votes |
def test_check_extraction(self): """Tests the check_extraction method.""" test_files = { 'bin': ['bzcat', 'echo'], 'sbin': ['visudo', 'tune2fs'], 'home': ['echo'] } for subfolder, files in test_files.items(): os.makedirs(os.path.join(self.extraction_dir, subfolder)) for file in files: os.mknod(os.path.join(self.extraction_dir, subfolder, file)) self.task.json_path = os.path.join(self.extraction_dir, 'hashes.json') self.task.binary_extraction_dir = self.extraction_dir binary_cnt, hash_cnt = self.task.check_extraction() self.assertEqual(binary_cnt, 5) self.assertEqual(hash_cnt, 4) # Test if hashes.json file is not generated. self.task.json_path = os.path.join(self.extraction_dir, 'non_exist') self.assertRaises(TurbiniaException, self.task.check_extraction)
Example #6
Source File: test_salt_artifact.py From heist with GNU General Public License v3.0 | 6 votes |
def test_get_artifact(self, mock_hub: testing.MockHub, tmp_path): ''' test heist.salt_master.get_artifact when artifact does not already exist ''' t_name = secrets.token_hex() ver = '2019.2.1' art_l = os.path.join(tmp_path, f'salt-{ver}') os.mknod(art_l) mock_hub.artifact.salt.fetch.return_value = art_l mock_hub.heist.salt_master.latest.return_value = False ret = await heist.artifact.salt_artifact.get_artifact(mock_hub, t_name, 'asyncssh', tmp_path, 'linux', ver) assert ret
Example #7
Source File: test_posix.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_mknod_dir_fd(self): # Test using mknodat() to create a FIFO (the only use specified # by POSIX). support.unlink(support.TESTFN) mode = stat.S_IFIFO | stat.S_IRUSR | stat.S_IWUSR f = posix.open(posix.getcwd(), posix.O_RDONLY) try: posix.mknod(support.TESTFN, mode, 0, dir_fd=f) except OSError as e: # Some old systems don't allow unprivileged users to use # mknod(), or only support creating device nodes. self.assertIn(e.errno, (errno.EPERM, errno.EINVAL)) else: self.assertTrue(stat.S_ISFIFO(posix.stat(support.TESTFN).st_mode)) finally: posix.close(f)
Example #8
Source File: upload_code.py From codo-publish with MIT License | 6 votes |
def rsync_tmp(self, host): """ 发布代码到目标主机的/tmp目录 :return: """ if not isinstance(host, dict): raise ValueError() ip = host.get('ip') port = host.get('port', 22) user = host.get('user', 'root') password = host.get('password') local_code_path = self.local_dir + self.repo_name # 处理后的本地代码路径 rsync_tmp_cmd = "sshpass -p {} rsync -ahqzt --delete -e 'ssh -p {} -o StrictHostKeyChecking=no ' {} {}@{}:{}".format( password, port, local_code_path, user, ip, '/tmp/') # print('[CMD:] ', rsync_tmp_cmd) rsync_status, rsync_output = exec_shell(rsync_tmp_cmd) if rsync_status == 0: # 同步完成删除/tmp/repo_name目录 print('[Success]: rsync host:{} to /tmp/{} sucess...'.format(ip, self.repo_name)) else: os.mknod(self.uuid_file) print('[Error]: rsync host:{} falied '.format(ip))
Example #9
Source File: common.py From spider with Apache License 2.0 | 6 votes |
def set_log(level, filename='spider.log'): """ return a log file object 根据提示设置log打印 """ if not os.path.isdir(LOG_DIR): os.mkdir(LOG_DIR) log_file = os.path.join(LOG_DIR, filename) if not os.path.isfile(log_file): os.mknod(log_file) os.chmod(log_file, 0777) log_level_total = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARN, 'error': logging.ERROR, 'critical': logging.CRITICAL} logger_f = logging.getLogger('spider') logger_f.setLevel(logging.DEBUG) fh = logging.FileHandler(log_file,'a') fh.setLevel(log_level_total.get(level, logging.DEBUG)) formatter = logging.Formatter('%(asctime)s %(filename)s [line:%(lineno)d] %(levelname)s %(message)s') fh.setFormatter(formatter) logger_f.addHandler(fh) keep_fds = [fh.stream.fileno()] return logger_f,keep_fds
Example #10
Source File: raw.py From dpdata with GNU Lesser General Public License v3.0 | 6 votes |
def dump (folder, data) : os.makedirs(folder, exist_ok = True) nframes = data['cells'].shape[0] np.savetxt(os.path.join(folder, 'type.raw'), data['atom_types'], fmt = '%d') np.savetxt(os.path.join(folder, 'type_map.raw'), data['atom_names'], fmt = '%s') np.savetxt(os.path.join(folder, 'box.raw'), np.reshape(data['cells'], [nframes, 9])) np.savetxt(os.path.join(folder, 'coord.raw'), np.reshape(data['coords'], [nframes, -1])) if 'energies' in data : np.savetxt(os.path.join(folder, 'energy.raw'), np.reshape(data['energies'], [nframes, 1])) if 'forces' in data : np.savetxt(os.path.join(folder, 'force.raw'), np.reshape(data['forces'], [nframes, -1])) if 'virials' in data : np.savetxt(os.path.join(folder, 'virial.raw'), np.reshape(data['virials'], [nframes, 9])) try: os.remove(os.path.join(folder, "nopbc")) except OSError: pass if data.get("nopbc", False): os.mknod(os.path.join(folder, "nopbc"))
Example #11
Source File: tarfile.py From recruit with Apache License 2.0 | 6 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #12
Source File: tarfile.py From Weapon-Detection-And-Classification with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #13
Source File: deploy_code.py From codo-publish with MIT License | 5 votes |
def code_deploy(self, host): if not isinstance(host, dict): raise ValueError() '''/tmp下的代码是upload_code脚本上传过来的''' tmp_code_path = '/tmp/{}'.format(self.repo_name) # if not os.path.exists(tmp_code_path): # print('[Error]: No code found') # sys.exit(-100) ip = host.get('ip') port = host.get('port', 22) user = host.get('user', 'root') password = host.get('password') # code_path = self.publish_path + self.repo_name # depoly_cmd = "sshpass -p {} rsync -ahqzt --delete -e 'ssh -p {} -o StrictHostKeyChecking=no ' {} {}@{}:{}".format( # password, port, tmp_code_path, user, ip, self.publish_path) rsync_cmd = 'rsync -ahqzt --delete {} {}'.format(tmp_code_path, self.publish_path) depoly_cmd = "sshpass -p {} ssh -p {} -o StrictHostKeyChecking=no {}@{} '{}'".format( password, port, user, ip, rsync_cmd) # print('[CMD:]', depoly_cmd) try: depoly_status, depoly_output = exec_shell(depoly_cmd) if depoly_status == 0: print('[Success]: Host:{} 发布成功'.format(ip)) else: os.mknod(self.uuid_file) print('[Error]: Host:{} 失败,错误信息: {}'.format(ip, depoly_output)) exit(-3) except Exception as e: print(e) exit(-500)
Example #14
Source File: tarfile.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #15
Source File: tarfile.py From planespotter with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #16
Source File: tarfile.py From scylla with Apache License 2.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #17
Source File: tarfile.py From scylla with Apache License 2.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #18
Source File: test_2650_UsercodeSandbox.py From dirigible-spreadsheet with MIT License | 5 votes |
def test_harold_tries_to_create_a_file_in_usr(self): # * Harold logs in and creates a new sheet self.login_and_create_new_sheet() # * He tries to create a file in the current dir self.prepend_usercode(dedent(''' import os os.mknod('/usr/lib/foo.txt') ''')[1:]) # * Dirigible notices his naughtiness and stops it self.wait_for_console_content(dedent(''' OSError: [Errno 13] Permission denied User code line 2''')[1:])
Example #19
Source File: paxtarfile.py From quay with Apache License 2.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """ Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #20
Source File: test_extra.py From enos with GNU General Public License v3.0 | 5 votes |
def test_seek_path(self, abspath, relpath): # Execution from the source directory with working_directory(self.sourcedir): self.assertPathEqual(seekpath(abspath), abspath, "Seeking for an %s defined " "with an absolute path should always " "return that path" % abspath) self.assertPathEqual(seekpath(relpath), os.path.join(const.ENOS_PATH, relpath), "Seeking for %s from the source directory" "should seek into enos source" % relpath) # Execution from a working directory with working_directory(self.workdir): self.assertPathEqual(seekpath(abspath), abspath, "Seeking for %s defined " "with an absolute path should always " "return that path" % abspath) self.assertPathEqual(seekpath(relpath), os.path.join(const.ENOS_PATH, relpath), "In absence of %s in the working " "directory, enos should seek for that one " "in sources" % relpath) # Build a fake `relpath` in the working directory and # check seekpath behaviour os.makedirs(os.path.dirname(relpath)) os.path.lexists(relpath) or os.mknod(relpath) self.assertPathEqual(seekpath(relpath), os.path.join(self.workdir, relpath), "In presence of %s in the working directory," "enos should take this one" % relpath)
Example #21
Source File: test_2650_UsercodeSandbox.py From dirigible-spreadsheet with MIT License | 5 votes |
def test_harold_tries_to_create_a_file_in_cwd(self): # * Harold logs in and creates a new sheet self.login_and_create_new_sheet() # * He tries to create a file in the current dir self.prepend_usercode(dedent(''' import os os.mknod('foo.txt') ''')[1:]) # * Dirigible notices his naughtiness and stops it self.wait_for_console_content(dedent(''' OSError: [Errno 13] Permission denied User code line 2''')[1:])
Example #22
Source File: tarfile.py From Imogen with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #23
Source File: tarfile.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #24
Source File: tarfile.py From ironpython3 with Apache License 2.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #25
Source File: tarfile.py From pySINDy with MIT License | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #26
Source File: tarfile.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #27
Source File: passthrough.py From gitfs with Apache License 2.0 | 5 votes |
def mknod(self, path, mode, dev): return os.mknod(self.repo._full_path(path), mode, dev)
Example #28
Source File: tarfile.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #29
Source File: tarfile.py From hacktoberfest2018 with GNU General Public License v3.0 | 5 votes |
def makedev(self, tarinfo, targetpath): """Make a character or block device called targetpath. """ if not hasattr(os, "mknod") or not hasattr(os, "makedev"): raise ExtractError("special devices not supported by system") mode = tarinfo.mode if tarinfo.isblk(): mode |= stat.S_IFBLK else: mode |= stat.S_IFCHR os.mknod(targetpath, mode, os.makedev(tarinfo.devmajor, tarinfo.devminor))
Example #30
Source File: rd.py From rubber-docker with MIT License | 5 votes |
def makedev(dev_path): for i, dev in enumerate(['stdin', 'stdout', 'stderr']): os.symlink('/proc/self/fd/%d' % i, os.path.join(dev_path, dev)) os.symlink('/proc/self/fd', os.path.join(dev_path, 'fd')) # Add extra devices DEVICES = {'null': (stat.S_IFCHR, 1, 3), 'zero': (stat.S_IFCHR, 1, 5), 'random': (stat.S_IFCHR, 1, 8), 'urandom': (stat.S_IFCHR, 1, 9), 'console': (stat.S_IFCHR, 136, 1), 'tty': (stat.S_IFCHR, 5, 0), 'full': (stat.S_IFCHR, 1, 7)} for device, (dev_type, major, minor) in DEVICES.iteritems(): os.mknod(os.path.join(dev_path, device), 0o666 | dev_type, os.makedev(major, minor))