From 0476871d3433761048fe79e07639586e68fc4a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volkan=20=C5=9Eahin?= Date: Wed, 29 Jun 2016 12:20:57 +0300 Subject: [PATCH] added new util feature and added file receive path to system --- opt/ahenk/base/system/system.py | 13 +++++++++++++ opt/ahenk/base/util/util.py | 14 +++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/opt/ahenk/base/system/system.py b/opt/ahenk/base/system/system.py index 3def19e..25e2fa2 100644 --- a/opt/ahenk/base/system/system.py +++ b/opt/ahenk/base/system/system.py @@ -12,6 +12,7 @@ import socket import fcntl import struct from uuid import getnode as get_mac +from base.util.util import Util from base.Scope import Scope @@ -84,6 +85,13 @@ class System: def pid_path(): return '/var/run/ahenk.pid' + @staticmethod + def received_dir_path(): + path = '/tmp/.ahenk/' + if Util.is_exist(path) is False: + Util.create_directory(path) + return path + class Process(object): @staticmethod @@ -205,6 +213,11 @@ class System: desktop = system.db_service.select_one_result('session', 'desktop', " username='{0}'".format(username)) return desktop + @staticmethod + def user_home_path(username): + # TODO temp + return '/home/{}/'.format(str(username)) + class Os(object): @staticmethod diff --git a/opt/ahenk/base/util/util.py b/opt/ahenk/base/util/util.py index dfa62d9..8b390c3 100644 --- a/opt/ahenk/base/util/util.py +++ b/opt/ahenk/base/util/util.py @@ -11,7 +11,7 @@ import stat import subprocess import hashlib import datetime - +import uuid class Util: def __init__(self): @@ -81,14 +81,14 @@ class Util: @staticmethod def read_file(full_path, mode='r'): - file = None + content = None try: - file = open(full_path, mode) - return file.read() + with open(full_path,mode) as f: + content = f.read() except: raise finally: - file.close() + return content @staticmethod def write_file(full_path, content, mode='w'): @@ -239,3 +239,7 @@ class Util: @staticmethod def timestamp(): return str(datetime.datetime.now().strftime("%d-%m-%Y %I:%M")) + + @staticmethod + def generate_uuid(): + return uuid.uuid4()