Пример #1
0
def change_match_file(file_name, edited_res):
    """Replace the file name of a resource"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    if dict(edited_res)[res_name] is not None:
        res_crypt_name = crypt_identifier(res_name)
        new_file_name = dir_name + res_crypt_name + file_ext  # Append the string
        u.rename(file_name, new_file_name)  # Rename the file
Пример #2
0
def change_match_file(file_name, edited_res):
    """Replace the file name of a resource"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    if dict(edited_res)[res_name] is not None:
        res_crypt_name = crypt_identifier(res_name)
        new_file_name = dir_name + res_crypt_name + file_ext  # Append the string
        u.rename(file_name, new_file_name)  # Rename the file
Пример #3
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    new_res_name = '!' + res_name + file_ext + '!'
    new_file_name = dir_name + new_res_name
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(class_crypt, apply_crypt(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Пример #4
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    new_res_name = '!' + res_name + file_ext + '!'
    new_file_name = dir_name + new_res_name
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(
            class_crypt, apply_crypt(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Пример #5
0
    def __call__(self,
                 path,
                 mode="r",
                 text=False,
                 atomictemp=False,
                 notindexed=False):
        '''Open ``path`` file, which is relative to vfs root.

        Newly created directories are marked as "not to be indexed by
        the content indexing service", if ``notindexed`` is specified
        for "write" mode access.
        '''
        if self._audit:
            r = util.checkosfilename(path)
            if r:
                raise util.Abort("%s: %r" % (r, path))
        self.audit(path)
        f = self.join(path)

        if not text and "b" not in mode:
            mode += "b"  # for that other OS

        nlink = -1
        if mode not in ('r', 'rb'):
            dirname, basename = util.split(f)
            # If basename is empty, then the path is malformed because it points
            # to a directory. Let the posixfile() call below raise IOError.
            if basename:
                if atomictemp:
                    util.ensuredirs(dirname, self.createmode, notindexed)
                    return util.atomictempfile(f, mode, self.createmode)
                try:
                    if 'w' in mode:
                        util.unlink(f)
                        nlink = 0
                    else:
                        # nlinks() may behave differently for files on Windows
                        # shares if the file is open.
                        fd = util.posixfile(f)
                        nlink = util.nlinks(f)
                        if nlink < 1:
                            nlink = 2  # force mktempcopy (issue1922)
                        fd.close()
                except (OSError, IOError) as e:
                    if e.errno != errno.ENOENT:
                        raise
                    nlink = 0
                    util.ensuredirs(dirname, self.createmode, notindexed)
                if nlink > 0:
                    if self._trustnlink is None:
                        self._trustnlink = nlink > 1 or util.checknlink(f)
                    if nlink > 1 or not self._trustnlink:
                        util.rename(util.mktempcopy(f), f)
        fp = util.posixfile(f, mode)
        if nlink == 0:
            self._fixfilemode(f)
        return fp
Пример #6
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    res_name = fix_invalid_file(res_name)
    new_res_name = '!' + res_name + '!'
    new_res_name = new_res_name.replace('$', '!$!')
    new_file_name = dir_name + new_res_name + file_ext
    new_file_name = defix_invalid_file(new_file_name)
    for class_crypt in re.findall(r'(\![^\!]*?\!)', new_file_name):
        new_file_name = new_file_name.replace(
            class_crypt, crypt_identifier(class_crypt[:-1][1:]))
    u.rename(file_name, new_file_name)
Пример #7
0
    def __call__(self, path, mode="r", text=False, atomictemp=False,
                 notindexed=False):
        '''Open ``path`` file, which is relative to vfs root.

        Newly created directories are marked as "not to be indexed by
        the content indexing service", if ``notindexed`` is specified
        for "write" mode access.
        '''
        if self._audit:
            r = util.checkosfilename(path)
            if r:
                raise util.Abort("%s: %r" % (r, path))
        self.audit(path)
        f = self.join(path)

        if not text and "b" not in mode:
            mode += "b" # for that other OS

        nlink = -1
        if mode not in ('r', 'rb'):
            dirname, basename = util.split(f)
            # If basename is empty, then the path is malformed because it points
            # to a directory. Let the posixfile() call below raise IOError.
            if basename:
                if atomictemp:
                    util.ensuredirs(dirname, self.createmode, notindexed)
                    return util.atomictempfile(f, mode, self.createmode)
                try:
                    if 'w' in mode:
                        util.unlink(f)
                        nlink = 0
                    else:
                        # nlinks() may behave differently for files on Windows
                        # shares if the file is open.
                        fd = util.posixfile(f)
                        nlink = util.nlinks(f)
                        if nlink < 1:
                            nlink = 2 # force mktempcopy (issue1922)
                        fd.close()
                except (OSError, IOError) as e:
                    if e.errno != errno.ENOENT:
                        raise
                    nlink = 0
                    util.ensuredirs(dirname, self.createmode, notindexed)
                if nlink > 0:
                    if self._trustnlink is None:
                        self._trustnlink = nlink > 1 or util.checknlink(f)
                    if nlink > 1 or not self._trustnlink:
                        util.rename(util.mktempcopy(f), f)
        fp = util.posixfile(f, mode)
        if nlink == 0:
            self._fixfilemode(f)
        return fp
Пример #8
0
 def finalize(self, tr):
     "finalize index updates"
     self.opener = self._realopener
     # move redirected index data back into place
     if self._delayname:
         util.rename(self._delayname + ".a", self._delayname)
     elif self._delaybuf:
         fp = self.opener(self.indexfile, 'a')
         fp.write("".join(self._delaybuf))
         fp.close()
         self._delaybuf = []
     # split when we're done
     self.checkinlinesize(tr)
Пример #9
0
 def flush(self):
     if self.isDirty():
         print "syncdb"
         output = []
         for l in self.lists:
             output.append({"name": l.name,
                            "id": l.id,
                            "items": l.items,
                            "users": list(l.channel.entitled)})
         json.dump(output, open(TEMP_PATH, "w"))
         rename(DATA_PATH, "%s/%d.txt" % (BACKUP_PATH, int(time.time())))
         rename(TEMP_PATH, DATA_PATH)
         self.clearDirty()
Пример #10
0
    def __call__(self, source, path, file_name, force_clear=True):
        if force_clear:
            util.rm_dir(path)

        self.getter(source, path)

        for _, _, files in os.walk(path):
            for name in files:
                tmp_name = name

        source_path = os.path.join(path, tmp_name)
        dest_path = os.path.join(path, file_name)
        util.rename(source_path, dest_path)
Пример #11
0
 def finalize(self, tr):
     "finalize index updates"
     self._delayed = False
     self.opener = self._realopener
     # move redirected index data back into place
     if self._divert:
         n = self.opener(self.indexfile + ".a").name
         util.rename(n, n[:-2])
     elif self._delaybuf:
         fp = self.opener(self.indexfile, 'a')
         fp.write("".join(self._delaybuf))
         fp.close()
         self._delaybuf = []
     # split when we're done
     self.checkinlinesize(tr)
Пример #12
0
 def finalize(self, tr):
     "finalize index updates"
     self._delayed = False
     self.opener = self._realopener
     # move redirected index data back into place
     if self._divert:
         nfile = self.opener(self.indexfile + ".a")
         n = nfile.name
         nfile.close()
         util.rename(n, n[:-2])
     elif self._delaybuf:
         fp = self.opener(self.indexfile, 'a')
         fp.write("".join(self._delaybuf))
         fp.close()
         self._delaybuf = []
     # split when we're done
     self.checkinlinesize(tr)
Пример #13
0
    def __call__(self, path, mode="r", text=False, atomictemp=False):
        if self._audit:
            r = util.checkosfilename(path)
            if r:
                raise util.Abort("%s: %r" % (r, path))
        self.auditor(path)
        f = self.join(path)

        if not text and "b" not in mode:
            mode += "b"  # for that other OS

        nlink = -1
        dirname, basename = os.path.split(f)
        # If basename is empty, then the path is malformed because it points
        # to a directory. Let the posixfile() call below raise IOError.
        if basename and mode not in ('r', 'rb'):
            if atomictemp:
                if not os.path.isdir(dirname):
                    util.makedirs(dirname, self.createmode)
                return util.atomictempfile(f, mode, self.createmode)
            try:
                if 'w' in mode:
                    util.unlink(f)
                    nlink = 0
                else:
                    # nlinks() may behave differently for files on Windows
                    # shares if the file is open.
                    fd = util.posixfile(f)
                    nlink = util.nlinks(f)
                    if nlink < 1:
                        nlink = 2  # force mktempcopy (issue1922)
                    fd.close()
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    raise
                nlink = 0
                if not os.path.isdir(dirname):
                    util.makedirs(dirname, self.createmode)
            if nlink > 0:
                if self._trustnlink is None:
                    self._trustnlink = nlink > 1 or util.checknlink(f)
                if nlink > 1 or not self._trustnlink:
                    util.rename(util.mktempcopy(f), f)
Пример #14
0
    def __call__(self, path, mode="r", text=False, atomictemp=False):
        if self._audit:
            r = util.checkosfilename(path)
            if r:
                raise util.Abort("%s: %r" % (r, path))
        self.auditor(path)
        f = os.path.join(self.base, path)

        if not text and "b" not in mode:
            mode += "b" # for that other OS

        nlink = -1
        dirname, basename = os.path.split(f)
        # If basename is empty, then the path is malformed because it points
        # to a directory. Let the posixfile() call below raise IOError.
        if basename and mode not in ('r', 'rb'):
            if atomictemp:
                if not os.path.isdir(dirname):
                    util.makedirs(dirname, self.createmode)
                return util.atomictempfile(f, mode, self.createmode)
            try:
                if 'w' in mode:
                    util.unlink(f)
                    nlink = 0
                else:
                    # nlinks() may behave differently for files on Windows
                    # shares if the file is open.
                    fd = util.posixfile(f)
                    nlink = util.nlinks(f)
                    if nlink < 1:
                        nlink = 2 # force mktempcopy (issue1922)
                    fd.close()
            except (OSError, IOError), e:
                if e.errno != errno.ENOENT:
                    raise
                nlink = 0
                if not os.path.isdir(dirname):
                    util.makedirs(dirname, self.createmode)
            if nlink > 0:
                if self._trustnlink is None:
                    self._trustnlink = nlink > 1 or util.checknlink(f)
                if nlink > 1 or not self._trustnlink:
                    util.rename(util.mktempcopy(f), f)
Пример #15
0
def rename_images(dir, prefix):
    files = os.listdir(dir)
    index = 1
    print("Renaming images")
    for f in files:
        if f.startswith("."):
            print("Escape {}".format(f))
            continue
        src = os.path.join(dir, f)
        name = rename(f, index, prefix)
        dst = os.path.join(dir, name)
        os.rename(src, dst)
        index = index + 1
    print("Finished renaming")
Пример #16
0
def test():
    util.rename('a.txt', 'a_.txt')
    return ret
Пример #17
0
            help='Do not emit backend assembly')
    ap.add_argument('-s', '--assembly', action='store_true',
            help='Emit assembly language and stop')
    ap.add_argument('files', nargs='*', default=[],
            help='Files to compile')

    args = ap.parse_args()
    for filename in args.files:
        p = subprocess.Popen(['cpp', '-undef', filename], stdout=subprocess.PIPE)
        f = p.stdout
        ast = parser.parse(f.read())
        f.close()


        if args.ast:
            with open(util.rename(filename, 'ast'), 'w') as af:
                print >>af, ast

        intermediate = iemit.emit(ast)
        if args.intermediate:
            with open(util.rename(filename, 'i'), 'w') as ir:
                for r in intermediate:
                    if isinstance(r, ia.Label):
                        print >>ir, r
                    else:
                        print >>ir, '   ', r

        if not args.no_assembly:
            backend = Backend(intermediate)
            asm = backend.generate()
            asmfile = util.rename(filename, 'asm')
Пример #18
0
 def rename(self, src, dst):
     return util.rename(self.join(src), self.join(dst))
Пример #19
0
def test_rename():
    ret = util.rename('d1/a.txt', 'd2/b.txt')
    return 'rename OK: ' + str(ret)
Пример #20
0
 def linker(filenames):
     outfile = util.rename(filenames[0], None)
     filenames = [util.rename(f, 'o') for f in filenames]
     return subprocess.call(['gcc', '-m32', '-o', outfile] + filenames)
Пример #21
0
def change_match_file(file_name):
    """Rename a class file appending the string"""
    dir_name, res_name, file_ext = u.get_file_info(file_name)
    u.rename(file_name, dir_name + 'lib' + crypt_identifier(res_name + file_ext) + file_ext)
Пример #22
0
 def rename(self, src, dst):
     return util.rename(self.join(src), self.join(dst))