diff options
author | emkael <emkael@tlen.pl> | 2017-10-02 23:48:02 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-10-02 23:48:02 +0200 |
commit | 19caef32a560a4a797fba4ab2fa93bc2b410039b (patch) | |
tree | 6b965e9e3320305517929d4792ec1948c51ec2a4 /jfr_playoff/filemanager.py | |
parent | 86654dee683d9a2cda00a528b006433cebeebf26 (diff) | |
parent | 40d09a61727d3c960a816def07fb319853a90116 (diff) |
Merge branch 'refactor'
Diffstat (limited to 'jfr_playoff/filemanager.py')
-rw-r--r-- | jfr_playoff/filemanager.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/jfr_playoff/filemanager.py b/jfr_playoff/filemanager.py new file mode 100644 index 0000000..5cd2a80 --- /dev/null +++ b/jfr_playoff/filemanager.py @@ -0,0 +1,53 @@ +import os +import shutil +import socket + +import __main__ + + +class PlayoffFileManager(object): + + def __init__(self, settings): + self.goniec = settings.get('goniec') + self.output_file = settings.get('output') + self.output_path = os.path.dirname( + self.output_file + ).strip(os.sep) + os.sep + self.files = set() + + def reset(self): + self.files.clear() + + def register_file(self, path): + if path.startswith(self.output_path): + self.files.add(path.replace(self.output_path, '')) + + def write_content(self, content): + output = open(self.output_file, 'w') + output.write(content.encode('utf8')) + output.close() + self.register_file(self.output_file) + return self.output_file + + def copy_scripts(self, script_path='sklady/playoff.js'): + script_output_path = os.path.join(self.output_path, script_path) + shutil.copy( + unicode(os.path.join( + os.path.dirname(__main__.__file__), 'playoff.js')), + unicode(script_output_path)) + self.register_file(script_output_path) + return script_output_path + + def send_files(self): + if self.goniec['enabled']: + try: + content_lines = [self.output_path] + \ + list(self.files) + \ + ['bye', ''] + print '\n'.join(content_lines) + goniec = socket.socket() + goniec.connect((self.goniec['host'], self.goniec['port'])) + goniec.sendall('\n'.join(content_lines)) + goniec.close() + except socket.error: + pass |