Exemplo n.º 1
0
def save(f):
    """Store temporary file, which is wiped once the request finishes."""
    filename = os.path.basename(f.filename)
    if os.path.exists(filename):
        abort(404, "file already found")
    if ".py" in filename or ".so" in filename:
        abort(403, "filename forbidden")

    f.save(filename)
    return tempfile(filename)
Exemplo n.º 2
0
def renderimages(images, width=80, height=80, space=0):
    import webbrowser

    template = os.path.dirname(
        os.path.realpath(__file__)) + '/template/images.html'
    rendered = renderhtml(template,
                          data=images,
                          width=width,
                          height=height,
                          space=space)
    tmp = tempfile('wt', '.html')
    tmp.write(rendered)
    tmp.flush()

    webbrowser.open(tmp.name)
    return tmp.name
Exemplo n.º 3
0
    def render(self, graph, output_type, destfile):
        if isinstance(destfile,file):
            filename = destfile.name
            destfile.close()
        elif isinstance(destfile,str):
            filename = destfile
        else:
            raise Exception
        temp = tempfile('.dot')
        graph._write_dot(temp)
        cmd = "%s -T%s -o%s %s" % (self._engine_executable, output_type, filename, temp)
        ier = os.system(cmd)
        if ier:
            check_graphviz_working()
            raise CLIRenderError("Error code %s rendering %s" % (ier, temp))

        os.remove(temp)
Exemplo n.º 4
0
    def render(self, graph, output_type, destfile):
        if isinstance(destfile, file):
            filename = destfile.name
            destfile.close()
        elif isinstance(destfile, str):
            filename = destfile
        else:
            raise Exception
        temp = tempfile('.dot')
        graph._write_dot(temp)
        cmd = "%s -T%s -o%s %s" % (self._engine_executable, output_type,
                                   filename, temp)
        ier = os.system(cmd)
        if ier:
            check_graphviz_working()
            raise CLIRenderError("Error code %s rendering %s" % (ier, temp))

        os.remove(temp)
Exemplo n.º 5
0
 def _temp_file(self):
     import tempfile
     tempfile = tempfile.NamedTemporaryFile
     kwargs = {'delete': True, 'mode': 'r+'}
     return tempfile(**kwargs)
Exemplo n.º 6
0
def opentf():
    import tempfile
    tempfile = tempfile.NamedTemporaryFile
    kwargs = {'delete': True, 'mode': 'r+'}
    return tempfile(**kwargs)
Exemplo n.º 7
0
'''

print('---------------6-----------------')
import shutil

# shutil.copy(src, dst) : src이름의 파일 내용을 dst 이름이 파일로 복사
shutil.copy('test', 'dst.txt')

print('----------------7----------------')
# glob 모듈 : 디렉토리에 있는 파일들을 리스트로 만들 때 사용
import glob

print(glob.glob('C:\\Users\\soldesk\\PycharmProjects\\workspace\\module3\\*'))

print('-----------------8--------------------')
'''
tempfile(임시파일) 모듈
 : 임시적으로 파일을 만들어서 사용할 때 유용한 모듈
 
 - tempfile.mktemp() : 임시로 파일을 만들어서 리턴
                     : 중복되지 않도록 만들어 줌
                     
 - tempfile.TemporaryFile() : 임시적인 저장공간으로 사용될 파일 객체를 리턴하는 함수
                          : w+b 모드를 갖는다
'''

import tempfile

fp = tempfile.mktemp()
print(fp)
Exemplo n.º 8
0
p = Popen(['sftp', '*****@*****.**'], stdout=PIPE, stdin=PIPE)    
p.stdin.write(b'LucLuc01')
time.sleep(0.5)
testresult = p.communicate()[0]
time.sleep(0.5)
print(testresult)



from subprocess import Popen, PIPE
print (Popen(['dir'],stdout=PIPE,stdin=PIPE).stdout.read())


from subprocess import Popen, PIPE
from tempfile import SpooledTemporaryFile as tempfile
f = tempfile()
f.write('one\ntwo\nthree\nfour\nfive\nsix\n')
f.seek(0)
print Popen(['/bin/grep','f'],stdout=PIPE,stdin=f).stdout.read()
f.close()




import time
from subprocess import Popen, PIPE
import subprocess

p = subprocess.Popen('dir',
                 stdout=subprocess.PIPE,
                 stderr=subprocess.STDOUT,
Exemplo n.º 9
0
def open_tempfile():
    """Open a temp file."""
    import tempfile
    tempfile = tempfile.NamedTemporaryFile
    kwargs = {'delete': True, 'mode': 'r+'}
    return tempfile(**kwargs)