def __init__(self, path=None): if path is None: path = conf.c['config_dir'] + 'default.lock' self.path = path if not shellutils.file_exists(path): shellutils.write_file(path, 'free')
def upload_script(name, data): full_path = conf.SCRIPTS_PATH + name sh.touch(full_path) shu.write_file(full_path, data) sh.chmod('u+x', full_path) return conf.mk_succ({'status': 'success'})
def write_dict_sexps(d): exp = [] for key in d: exp.append([key, d[key]]) sexps = json.dumps(exp) shutil.write_file(fname, sexps)
def add_key(key): keys_path = '/root/.ssh/authorized_keys' if not shu.file_exists(keys_path): sh.mkdir('-p', '/root/.ssh') sh.touch(keys_path) auth_keys = str(sh.cat('/root/.ssh/authorized_keys')) if key in auth_keys: print('!!!!!!!!!!key already added') else: print('!!!!adding ssh key') auth_keys += '\n\n' + key shu.write_file(keys_path, auth_keys) return conf.mk_succ({'status': 'success'})
def dw_song(link, i, tot): song_name = link.split('/')[-1] song_name_clean = song_name.\ replace('(', '__OP__').\ replace(')', '__CP__').\ replace('[', '__OB__').\ replace(']', '__CB__').\ replace('(c)', 'C') print('[%i/%i] %s' % (i, tot, link)) song_resp = requests.get(link) if song_resp.status_code != 200: print('bad song failed (%s)\n\t%s' % (song_name_clean, link)) song_data = song_resp.content shu.write_file('songs/' + song_name_clean, song_data, binary=True) pass
#!/usr/bin/python3 #sudo pip3 install sexpdata import sys from utiltools import shellutils as shutil from sexpdata import loads, dumps import json import sh fname = '/tmp/shellu' if not shutil.file_exists(fname): shutil.write_file(fname, '{}') def get_dict_sexps(): ret = {} data = shutil.read_file(fname) sexps_data = json.loads(data) for binding in sexps_data: ret[binding[0]] = binding[1] return ret def get_dict(): ret = {}
def lock(self, wait_increments=0.1): import time while self.is_locked(): time.sleep(wait_increments) shellutils.write_file(self.path, 'locked')
def unlock(self): shellutils.write_file(self.path, 'free')