mirror of
https://pagure.io/fedora-infra/ansible.git
synced 2026-03-20 12:07:34 +08:00
Get rid of temporary files alltogether
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
@@ -3,11 +3,9 @@
|
||||
from __future__ import unicode_literals, print_function
|
||||
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def main():
|
||||
@@ -21,11 +19,6 @@ def main():
|
||||
print('An username is required to query datagrepper')
|
||||
return 1
|
||||
|
||||
tempfilename = '/tmp/sar_{0}_{1}'.format(username, ''.join(
|
||||
[random.choice(string.ascii_letters + string.digits)
|
||||
for n in xrange(10)]
|
||||
))
|
||||
|
||||
# Get all messages related to this user.
|
||||
query = '''
|
||||
COPY (
|
||||
@@ -41,17 +34,11 @@ COPY (
|
||||
WHERE messages.username = '{username}'
|
||||
)
|
||||
)
|
||||
TO '{tmpfile}' delimiter ',' CSV header;
|
||||
TO STDOUT delimiter ',' CSV header;
|
||||
'''
|
||||
query = query.format(username=username, tmpfile=tempfilename)
|
||||
command = ['sudo', '-u', 'postgres', 'psql', 'datanommer', '-c', '"%s"' % query]
|
||||
subprocess.check_call(
|
||||
' '.join(command), shell=True, stdout=subprocess.PIPE,
|
||||
cwd='/tmp')
|
||||
with open(tempfilename) as stream:
|
||||
for line in stream:
|
||||
print(line)
|
||||
os.unlink(tempfilename)
|
||||
subprocess.check_call(' '.join(command), shell=True, cwd='/tmp')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user