Example #1
0
 def getfile(fname, dir, label):
     file = os.path.join(qtlib.gettempdir(), dir, fname)
     if os.path.isfile(file):
         return fname+label, file
     nullfile = os.path.join(qtlib.gettempdir(), 'empty')
     fp = open(nullfile, 'w')
     fp.close()
     return (hglib.fromunicode(_nonexistant, 'replace') + label,
             nullfile)
Example #2
0
 def getfile(fname, dir, label):
     file = os.path.join(qtlib.gettempdir(), dir, fname)
     if os.path.isfile(file):
         return fname + label, file
     nullfile = os.path.join(qtlib.gettempdir(), 'empty')
     fp = open(nullfile, 'w')
     fp.close()
     return (hglib.fromunicode(_nonexistant, 'replace') + label,
             nullfile)
Example #3
0
def snapshot(repo, files, ctx):
    '''snapshot files as of some revision'''
    dirname = os.path.basename(repo.root) or 'root'
    dirname += '.%d' % _diffCount
    if ctx.rev() is not None:
        dirname += '.%d' % ctx.rev()
    base = os.path.join(qtlib.gettempdir(), dirname)
    fns_and_mtime = []
    if not os.path.exists(base):
        os.mkdir(base)
    for fn in files:
        wfn = util.pconvert(fn)
        if not wfn in ctx:
            # File doesn't exist; could be a bogus modify
            continue
        dest = os.path.join(base, wfn)
        if os.path.exists(dest):
            # File has already been snapshot
            continue
        destdir = os.path.dirname(dest)
        if not os.path.isdir(destdir):
            os.makedirs(destdir)
        data = repo.wwritedata(wfn, ctx[wfn].data())
        f = open(dest, 'wb')
        f.write(data)
        f.close()
        if ctx.rev() is None:
            fns_and_mtime.append((dest, repo.wjoin(fn), 
                                  os.lstat(dest).st_mtime))
        else:
            # Make file read/only, to indicate it's static (archival) nature
            os.chmod(dest, stat.S_IREAD)
    return base, fns_and_mtime
Example #4
0
def _writetempfile(text):
    fd, filename = tempfile.mkstemp(suffix='.patch', prefix='thg-import-',
                                    dir=qtlib.gettempdir())
    try:
        os.write(fd, text)
    finally:
        os.close(fd)
    return filename
Example #5
0
 def writetempfile(s):
     fd, fname = tempfile.mkstemp(prefix='thg_emaildesc_',
                                  dir=qtlib.gettempdir())
     try:
         os.write(fd, s)
         return hglib.tounicode(fname)
     finally:
         os.close(fd)
Example #6
0
    def _tempwebconf(self):
        """Save current webconf to temporary file; return its path"""
        if not hasattr(self._webconf, 'write'):
            return self._webconf.path

        fd, fname = tempfile.mkstemp(prefix='webconf_', dir=qtlib.gettempdir())
        f = os.fdopen(fd, 'w')
        try:
            self._webconf.write(f)
            return fname
        finally:
            f.close()
Example #7
0
 def getfile(ctx, dir, fname, source):
     m = ctx.manifest()
     if fname in m:
         path = os.path.join(dir, util.localpath(fname))
         return fname, path
     elif source and source in m:
         path = os.path.join(dir, util.localpath(source))
         return source, path
     else:
         nullfile = os.path.join(qtlib.gettempdir(), 'empty')
         fp = open(nullfile, 'w')
         fp.close()
         return hglib.fromunicode(_nonexistant, 'replace'), nullfile
Example #8
0
 def getfile(ctx, dir, fname, source):
     m = ctx.manifest()
     if fname in m:
         path = os.path.join(dir, util.localpath(fname))
         return fname, path
     elif source and source in m:
         path = os.path.join(dir, util.localpath(source))
         return source, path
     else:
         nullfile = os.path.join(qtlib.gettempdir(), 'empty')
         fp = open(nullfile, 'w')
         fp.close()
         return hglib.fromunicode(_nonexistant, 'replace'), nullfile
Example #9
0
def snapshot(repo, files, ctx):
    '''snapshot files as of some revision'''
    dirname = os.path.basename(repo.root) or 'root'
    dirname += '.%d' % _diffCount
    if ctx.rev() is not None:
        dirname += '.%d' % ctx.rev()
    base = os.path.join(qtlib.gettempdir(), dirname)
    fns_and_mtime = []
    if not os.path.exists(base):
        os.makedirs(base)
    for fn in files:
        wfn = util.pconvert(fn)
        if not wfn in ctx:
            # File doesn't exist; could be a bogus modify
            continue
        dest = os.path.join(base, wfn)
        if os.path.exists(dest):
            # File has already been snapshot
            continue
        destdir = os.path.dirname(dest)
        try:
            if not os.path.isdir(destdir):
                os.makedirs(destdir)
            data = repo.wwritedata(wfn, ctx[wfn].data())
            f = open(dest, 'wb')
            f.write(data)
            f.close()
            if ctx.rev() is None:
                fns_and_mtime.append(
                    (dest, repo.wjoin(fn), os.lstat(dest).st_mtime))
            else:
                # Make file read/only, to indicate it's static (archival) nature
                os.chmod(dest, stat.S_IREAD)
        except EnvironmentError:
            pass
    return base, fns_and_mtime