示例#1
0
文件: Tools.py 项目: InnovAnon-Inc/py
 def mountPartitions(self):
     print("mount partitions")
     if not self.is_persistent or not isdir(self.lfs):
         _eintr_retry_call(mkdir, self.lfs)
     check_call(['losetup', self.lo, self.path],
                stdin=DEVNULL,
                stdout=DEVNULL)
     check_call(['mount', '-t', self.fstype, self.lo, self.lfs],
                stdin=DEVNULL,
                stdout=DEVNULL)
示例#2
0
文件: Tools.py 项目: InnovAnon-Inc/py
 def createDisk(self):
     print("create disk")
     #if exists(self.pathdir): return
     self.createImagePath()
     """ https://stackoverflow.com/questions/12654772/create-empty-file-using-python """
     basedir = _eintr_retry_call(dirname, self.path)
     if not exists(basedir): _eintr_retry_call(makedirs, basedir)
     """ https://www.tutorialspoint.com/python/file_truncate.htm """
     with open(self.path, 'wb') as f:
         _eintr_retry_call(lambda F: F.truncate(self.sz), f)
示例#3
0
文件: Tools.py 项目: InnovAnon-Inc/py
 def downloadSources(self):
     print("download sources")
     if not _eintr_retry_call(isdir, self.sources):
         _eintr_retry_call(mkdir, self.sources)
     _eintr_retry_call(chmod_a_plus_wt, self.sources)
     # TODO
     #wget --input-file=wget-list --continue --directory-prefix=$LFS/sources
     wgetList = "%s/wget-list" % self.lfs_dns
     md5sums = "%s/md5sums" % self.lfs_dns
     missing_urls, missing_hashes, correct_hashes, failed_hashes = phash_c_download_stats(
         wgetList, md5sums, self.sources)
     print("correct hashes: %s" % correct_hashes)
     """
示例#4
0
文件: Tools.py 项目: InnovAnon-Inc/py
 def removeLFSUser(self):
     print("remove LFS user")
     ##restore_eprivileges(self.groups, self.old_umask)
     ##admin.deleteUser(jimbo)
     ##admin.removeHome(jimbo)
     ##admin.removeMail(jimbo)
     home = _eintr_retry_call(getpwnam, self.user).pw_dir
     check_call(['userdel', self.user], stdin=DEVNULL, stdout=DEVNULL)
     ##check_call(['groupdel', self.user])
     ## TODO
     ##home = expanduser("~%s" % self.user)
     ##home = "/home/%s" % self.user
     _eintr_retry_call(rmtree, home)
示例#5
0
    def setupEnvironment(self):
        print("setup environment")
        home = _eintr_retry_call(getpwnam, self.user).pw_dir

        def cp(x):
            _eintr_retry_call(copyfile, x, join(home, x))

        #t1 = Thread(target=cp, args=[".bash_profile"])
        #t2 = Thread(target=cp, args=[".bashrc"])
        #t1.start()
        #t2.start()
        #t1.join()
        #t2.join()
        def sed(x):
            with open(x, 'r') as f:
                s = f.read()
            s.replace('/mnt/lfs', self.lfs)
            s.replace('LFS_TGT=$(uname -m)-lfs-linux-gnu', self.lfs_tgt)
            with open(join(home, x), 'w') as f:
                f.write(s)

        parallelize([
            (sed, [".bash_profile"]),
            # TODO sed /mnt/lfs with self.lfs
            (cp, [".bashrc"])
        ])
        """ https://stackoverflow.com/questions/8365394/set-environment-variable-in-python-script#8365493 """
        term = os.environ['TERM']
        os.environ = {
            'HOME':
            home,
            'TERM':
            term,
            'PS1':
            """\\u:\\w\\$ """,
            'LFS':
            self.lfs,
            'LC_ALL':
            'POSIX',
            'LFS_TGT':
            '%s-lfs-linux-gnu' % uname()[4],
            'PATH':
            ':'.join([
                join(self.toolsym, 'bin'),
                join(sep, 'bin'),
                join(sep, 'usr', 'bin')
            ])
        }

        umask(0o22)
示例#6
0
def dropChildPrivileges(child, uid_name='nobody', gid_name='nogroup'):
    #try:
    pid = fork()
    #except OSError:

    if pid is 0:
        try:
            drop_privileges(uid_name=uid_name, gid_name=gid_name)
            child()
        #finally: _exit(0)
        except:
            _exit(2)
        _exit(0)
    #waitpid(pid, 0)
    cid, es = _eintr_retry_call(waitpid, pid, 0)
    if es: raise Exception()
示例#7
0
 def cp(x):
     _eintr_retry_call(copyfile, x, join(home, x))