Example #1
0
def add_mark(components, mark):
    """
    Case Mark.NONE will be deal with separately by user
    """
    comp = list(components)
    if mark == Mark.BAR and comp[0] and comp[0][-1].lower() in FAMILY_D:
        comp[0] = add_mark_at(comp[0], len(comp[0])-1, Mark.BAR)
    else:
        #remove all marks and accents in vowel part
        raw_vowel = accent.add_accent(comp, Accent.NONE)[1].lower()
        raw_vowel = utils.join([add_mark_char(c, Mark.NONE) for c in raw_vowel])
        if mark == Mark.HAT:
            pos = max(raw_vowel.find(u"a"), raw_vowel.find(u"o"),
                      raw_vowel.find(u"e"))
            comp[1] = add_mark_at(comp[1], pos, Mark.HAT)
        elif mark == Mark.BREVE:
            if raw_vowel != u"ua":
                comp[1] = add_mark_at(comp[1], raw_vowel.find(u"a"), Mark.BREVE)
        elif mark == Mark.HORN:
            if raw_vowel in (u"uo", u"uoi", u"uou"):
                comp[1] = utils.join([add_mark_char(c, Mark.HORN) for c in comp[1][:2]]) + comp[1][2:]
            elif raw_vowel == u"oa":
                comp[1] = add_mark_at(comp[1], 1, Mark.HORN)
            else:
                pos = max(raw_vowel.find(u"u"), raw_vowel.find(u"o"))
                comp[1] = add_mark_at(comp[1], pos, Mark.HORN)
    return comp
Example #2
0
    def __init__(self,
                 path,
                 file_num,
                 lr_size=96,
                 upscale=3,
                 dtype=np.uint8,
                 rgb=1):
        hr_size = lr_size * upscale
        self.file_num = file_num
        path = path

        input_list = sorted(glob(join(path, "input_*.raw")))
        label_list = sorted(glob(join(path, "label_*.raw")))
        permuted_list = np.arange(0, len(input_list))
        np.random.shuffle(permuted_list)
        self.input = list()
        self.label = list()
        for i in tqdm(range(file_num)):
            input = readraw(input_list[permuted_list[file_num]], dtype=dtype)
            label = readraw(label_list[permuted_list[file_num]], dtype=dtype)
            input = np.reshape(input, [-1, lr_size, lr_size, 3])
            label = np.reshape(label, [-1, hr_size, hr_size, 3])
            if rgb == 0:
                input = input[:, :, :, ::-1]
                label = label[:, :, :, ::-1]

            self.input.append(input)
            self.label.append(label)
        self.input = np.concatenate(self.input, axis=0)
        self.label = np.concatenate(self.label, axis=0)
Example #3
0
def add_mark(components, mark):
    """
    Case Mark.NONE will be deal with separately by user
    """
    comp = list(components)
    if mark == Mark.BAR and comp[0] and comp[0][-1].lower() in FAMILY_D:
        comp[0] = add_mark_at(comp[0], len(comp[0]) - 1, Mark.BAR)
    else:
        #remove all marks and accents in vowel part
        raw_vowel = accent.add_accent(comp, Accent.NONE)[1].lower()
        raw_vowel = utils.join(
            [add_mark_char(c, Mark.NONE) for c in raw_vowel])
        if mark == Mark.HAT:
            pos = max(raw_vowel.find(u"a"), raw_vowel.find(u"o"),
                      raw_vowel.find(u"e"))
            comp[1] = add_mark_at(comp[1], pos, Mark.HAT)
        elif mark == Mark.BREVE:
            if raw_vowel != u"ua":
                comp[1] = add_mark_at(comp[1], raw_vowel.find(u"a"),
                                      Mark.BREVE)
        elif mark == Mark.HORN:
            if raw_vowel in (u"uo", u"uoi", u"uou"):
                comp[1] = utils.join(
                    [add_mark_char(c, Mark.HORN)
                     for c in comp[1][:2]]) + comp[1][2:]
            elif raw_vowel == u"oa":
                comp[1] = add_mark_at(comp[1], 1, Mark.HORN)
            else:
                pos = max(raw_vowel.find(u"u"), raw_vowel.find(u"o"))
                comp[1] = add_mark_at(comp[1], pos, Mark.HORN)
    return comp
Example #4
0
def incomplete():
    log("incomplete:")
    active_nzbname_list, nzbname_list = nzbname_lists()
    nzoid_history_list = [x[1] for x in nzbname_list if x[1] is not None]
    for row in active_nzbname_list:
        url = "&nzoid=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\
              "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\
              "&folder=" + utils.quote_plus(row[0])
        info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0]))
        info.info_labels['title'] = "Active - " + info.info_labels['title']
        add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail,
                  info.fanart)
    for row in nzbname_list:
        if row[1]:
            url = "&nzoidhistory=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\
                  "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\
                  "&folder=" + utils.quote_plus(row[0])
            info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0]))
            add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST,
                      info.thumbnail, info.fanart)
        else:
            # Clean out a failed SABnzbd folder removal
            utils.dir_exists(utils.join(INCOMPLETE_FOLDER, row[0]), None)
    xbmcplugin.setContent(HANDLE, 'movies')
    xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True)
    return
Example #5
0
File: lspc.py Project: danr/libkak
def info_somewhere(msg, pos, where):
    """
    where = cursor | info | docsclient | echo
    """
    if not msg:
        return
    msg = msg.rstrip()
    if where == 'cursor':
        return 'info -placement above -anchor {} {}'.format(
            format_pos(pos),
            utils.single_quoted(utils.join(msg.split('\n')[0:10], '\n')))
    elif where == 'info':
        return 'info ' + utils.single_quoted(
            utils.join(msg.split('\n')[0:20], '\n'))
    elif where == 'docsclient':
        tmp = tempfile.mktemp()
        open(tmp, 'wb').write(utils.encode(msg))
        return """
            eval -no-hooks -try-client %opt[docsclient] %[
              edit! -scratch '*doc*'
              exec \%d|cat<space> {tmp}<ret>
              exec \%|fmt<space> - %val[window_width] <space> -s <ret>
              exec gg
              set buffer filetype rst
              try %[rmhl number_lines]
              %sh[rm {tmp}]
            ]""".format(tmp=tmp)
    elif where == 'echo':
        return 'echo ' + utils.single_quoted(msg.split('\n')[-1])
Example #6
0
def orig_implementation(num):
    """
        append fragmented digits to acc

        for every number list for last int:
            1. add 1 to its start, add each to new list
            2. for every digit in the number
                2.1 if it's smaller than the digit after it, or if there's no digit after it,
                    increment the digit by one and new number combo to new list
    """
    curr_n, combos = 2, [[1, 1]]

    while curr_n < num:
        curr_n += 1
        new_combos = {utils.join([1] * curr_n, True): [1] * curr_n}

        for c in combos:
            new_combos[utils.join([1] + c, True)] = [1] + c

            # 2 increment first if it's not bigger than the one after it
            if c[0] < c[1]:
                inc_first_digit = [c[0] + 1] + c[1:]
                new_combos[utils.join(inc_first_digit, True)] = inc_first_digit

            # 3. increment last digit
            inc_last_digit = c[:-1] + [c[-1] + 1]
            new_combos[utils.join(inc_last_digit, True)] = inc_last_digit
        combos = new_combos.values()
    return set([tuple(c) for c in combos])


# print([utils.join(i, True) for i in orig_implementation(7)])
# 50 in 19 seconds
# 60 in 25 seconds
# print orig_implementation(12).difference(counting_summations(12))
Example #7
0
def read_clfs(path):
    clfs = [None for i in range(6)]
    for i in range(1, 6 + 1):
        clfs[i - 1] = joblib.load(utils.join(path,
                                             str(i) + ".pkl"))

    fclf = joblib.load(utils.join(path, "fclf.pkl"))
    return clfs, fclf
Example #8
0
    def output(self, path, data, writefits=False, **kwargs):
        if writefits:
            self.write_fits(path, data, join(self.outdir, "fits", path + ".fits"))
        elif self.do_filter:
            self.write_fits(path, data, join(self.outdir, "fits_filtered", path + ".fits"))
        elif self.do_extract:
            self.extract(path, path + ".fits")

        if self.do_image:
            self.png(path, data, **kwargs)
Example #9
0
def complete(line, column, timestamp, completions):
    u"""
    Format completion for a Kakoune option.

    >>> print(complete(5, 20, 1234, [
    ...     ('__doc__', 'object’s docstring', '__doc__ (method)'),
    ...     ('||', 'logical or', '|| (func: infix)')
    ... ]))
    5.20@1234:__doc__|object’s docstring|__doc__ (method):\|\||logical or|\|\| (func\: infix)
    """
    rows = (utils.join((utils.backslash_escape('|:', x) for x in c), sep='|')
            for c in completions)
    return u'{}.{}@{}:{}'.format(line, column, timestamp,
                                 utils.join(rows, sep=':'))
Example #10
0
    def read(self):
        info, imgs = get_imgs(self.url)

        # 1225
        artist = join(info['artists'])
        self.artist = artist
        group = join(info['groups']) if info['groups'] else u'N/A'
        lang = info['language'][0] if info['language'] else u'N/A'
        series = info['parodies'][0] if info['parodies'] else u'N/A'
        title = self.format_title(info['category'][0], info['id'], info['title'], artist, group, series, lang)

        self.urls += imgs

        self.title = title
Example #11
0
 def extract(self, path, in_file):
     sex_file = tempfile.NamedTemporaryFile()
     checkfile = join(self.outdir, "extracted", path + ".fits")
     sex_file.write(
         open("template.sex")
         .read()
         .format(join(self.outdir, "cat", path + ".cat"), checkfile, ("FULL" if self.verbose == 2 else "QUIET"))
     )
     sex_file.flush()
     sex_file.seek(0)
     command = ["sextractor", "-c", sex_file.name, in_file]
     if self.verbose == 2:
         print " ".join(command)
     subprocess.call(command)
     self.png(os.path.join("extracted", path), pyfits.getdata(checkfile, 0))
    def read(self):
        info = self.info

        artist = join(info['artists'])
        self.artist = artist if info['artists'] else None
        group = join(info['groups'])
        lang = info['lang'] or 'N/A'
        series = info['seriess'][0] if info['seriess'] else 'N/A'
        title = self.format_title(info['type'], info['id'], info['title'],
                                  artist, group, series, lang)

        for img in info['imgs']:
            self.urls.append(img.url)

        self.title = title
Example #13
0
    def read(self):
        info, imgs = get_imgs(self.id)

        # 1225
        artist = join(info.artists)
        self.customWidget.artist = artist if info.artists else None
        group = join(info.groups) if info.groups else 'N/A'
        lang = info.lang if info.lang else 'N/A'
        series = info.seriess[0] if info.seriess else 'N/A'
        title = self.format_title(info.type, info.id, info.title, artist, group, series, lang)

        for img in imgs:
            self.urls.append(img.url)

        self.title = title
Example #14
0
 def save(self):
     strm_path = utils.join(self.folder, ('%s.strm' % self.nzbname))
     nzb_path = utils.join(self.folder, ('%s.nzb' % self.nzbname))
     nzb = urllib.quote_plus(self.nzb)
     nzbname = urllib.quote_plus(self.nzbname)
     if utils.exists(strm_path):
         log("StrmFile: save: replacing .strm file: %s" % strm_path.encode("utf_8"))
     line = "plugin://plugin.program.pneumatic/?mode=strm&nzb=" + nzb +\
                    "&nzbname=" + nzbname
     try: 
         utils.write(strm_path, line, 'wb')
     except:
         log("StrmFile: save: failed to create .strm file: %s" % strm_path.encode("utf_8"))
     if utils.exists(nzb_path):
         log("StrmFile: save: replacing .nzb file: %s" % nzb_path.encode("utf_8"))
     m_nzb.save(self.nzb, nzb_path)
Example #15
0
 def save(self):
     show_name = None
     if self.rageid is not None:
         show_name = self.rageid_show_name(self.rageid)
         if show_name is not None:
             show_name = unicode(show_name, 'utf-8')
     if show_name is None:
         manual_name = unikeyboard(self.nzbname, 'Enter show name')
         if manual_name is None:
             log("Tvshow: save: did not recieve a name for the TV-show")
             return
         #show_name = manual_name.decode("utf_8").encode("raw_unicode_escape")
         show_name = unicode(manual_name, 'utf-8').replace('\n','')
     strm_path_show = utils.join(self.strm_path, os.path.join(remove_disallowed_filename_chars(show_name),''))
     # Check if showname folder exist in path, if not create it.
     if not utils.exists(strm_path_show):
         try:
             utils.mkdir(strm_path_show)
         except:
             log("Tvshow: save: failed to create TV-show folder %s" % strm_path_show)
             return
     # Check if tvshow.nfo is there, if not, create it.
     tv_nfo = self.info
     tv_nfo.path(strm_path_show)
     # The Episode name has to be picked up by XBMC
     # regexps
     episode_name = self.check_episode_name(self.nzbname)
     if not self.save_nfo_type == "disabled":
         if self.save_nfo_type == "minimal":
             tv_nfo.mini()
         if not utils.exists(os.path.join(strm_path_show, 'tvshow.nfo')):
             tv_nfo.save_tvshow(show_name)
         # now, save the episodename.nfo
         tv_nfo.save_episode(episode_name)
     strm.StrmFile(strm_path_show, episode_name, self.nzb).save()
Example #16
0
def main() -> int:
    args = parse_args()
    estimator = utils.Estimator(args)

    if args.estimate:
        return print(estimator.estimate()) or 0
    elif args.estimate_size or args.estimate_time or args.estimate_ammount:
        if args.estimate_size:
            return print(estimator.estimate_size()) or 0
        elif args.estimate_time:
            return print(estimator.estimate_time()) or 0
        elif args.estimate_ammount:
            return print(estimator.estimate_ammount()) or 0

    with open(f'{args.path}/{args.file}', 'wb+') as f:
        [
            f.write(
                bytes(utils.join(c, args.separator, args.prefix, args.suffix),
                      'utf-8')) for c in rockyou.rockyou(
                          args.min_length, args.max_length, args.character_set)
        ]

        f.seek(-1, os.SEEK_END)
        f.truncate()

    return 0
Example #17
0
	def load(self, i=None):
		if i is None:
			files, idxs = ls_model(self.fdir, self.fname, self.fext)
			if len(files) > 0:  # 있으면 가장 최신을 로드
				self.model.load_state_dict(torch.load(files[-1]))
				print("util_pt.saver.Saver.load: loaded {}".format(files[-1]))
				return latest_idx(self.fdir, self.fname)
			else:  # 로드 안함
				basename = join(self.fdir, self.fname)
				print("util_pt.saver.Saver.load: {} not exist".format(basename))
				return 0
		else:
			fpath = join(self.fdir, r"{}-{}.{}".format(self.fname, i, self.fext))
			self.model.load_state_dict(torch.load(fpath))
			print("util_pt.saver.Saver.load: loaded {}".format(fpath))
			return i
Example #18
0
 def __getitem__(self, index):
     filenumber = self.file_list[index]
     filename = coco.loadImgs(filenumber)[0]["file_name"]
     image = Image.open(join(self.root, filename))
     image = transform(image)
     label = coco_to_yolo(filenumber, root=self.root)
     return image, label
Example #19
0
def save_strm(nzbname, url):
    log("save_strm: nzbname: %s url: %s" % (nzbname, url))
    strm2lib.save_strm(__settings__, nzbname, url)
    if SAVE_NZB and utils.exists(NZB_CACHE):
        nzb_path = utils.join(NZB_CACHE, '%s%s' % (nzbname, '.nzb'))
        log("save_strm: nzb_path: %s" % nzb_path)
        m_nzb.save(url, nzb_path)
Example #20
0
def dump_text(url, out, fmt='%05d.txt', max_size=None, fid=1, max_fid=2500):
    utils.mkdir(out)
    fn = utils.join(out, fmt)

    if max_size is None:
        max_size = 4 * 1024 * 1024

    zm = ZhhanzMan()
    zc = ZhCalc()

    fout = utils.openfile(fn % fid, 'w')
    records = []

    for text in extract_text(url):
        prop = zc.calc(text)
        if zc.calc(text) > 1e-2:
            records.append(prop)
            fout.write(zm.s2t(text))

        ft = fout.tell()
        progress = (ft / max(ft, max_size)) * 100
        print(end=f'FID: {fid}/{max_fid}, File Size: {progress:5.2f}%\r')

        if fout.tell() >= max_size:
            fout.close()
            fid += 1
            if fid > max_fid:
                break
            fout = utils.openfile(fn % fid, 'w')

    fout.close()

    with open('statistic.pkl', 'wb') as pkl:
        import pickle as pk
        pk.dump(records, pkl)
Example #21
0
def save_strm(nzbname, url):
    log("save_strm: nzbname: %s url: %s" % (nzbname, url))
    strm2lib.save_strm(__settings__, nzbname, url)
    if SAVE_NZB and utils.exists(NZB_CACHE):
        nzb_path = utils.join(NZB_CACHE, '%s%s' % (nzbname, '.nzb'))
        log("save_strm: nzb_path: %s" % nzb_path)
        m_nzb.save(url, nzb_path)
Example #22
0
def test_join():
    t1, t2 = get_test_trees()

    t3 = join(t1, t2)

    print("T1, T2 Joined:")
    print(t3)
def reverse(components, trans):
    """
    Reverse the effect of transformation 'trans' on 'components'
    If the transformation does not effect the components, return the original string
    Workflow:
    - Find the part of components that is effected by the transformation
    - Transform this part to the original state (remove accent if the trans
    is ADD_ACCENT action, remove mark if the trans is ADD_MARK action)
    """
    action, factor = get_action(trans)
    comps = list(components)
    string = utils.join(comps)

    if action == Action.ADD_CHAR and string[-1] == trans[1]:
        if comps[2]: i = 2
        elif comps[1]: i = 1
        else: i = 0
        comps[i] = comps[i][:-1]
    elif action == Action.ADD_ACCENT:
        comps = accent.add_accent(comps, Accent.NONE)
    elif action == Action.ADD_MARK:
        if factor == Mark.BAR:
            comps[0] = comps[0][:-1] + \
                mark.add_mark_char(comps[0][-1:], Mark.NONE)
        else:
            if mark.is_valid_mark(comps, trans):
                comps[1] = u"".join(
                    [mark.add_mark_char(c, Mark.NONE) for c in comps[1]])
    return comps
def reverse(components, trans):
    """
    Reverse the effect of transformation 'trans' on 'components'
    If the transformation does not effect the components, return the original string
    Workflow:
    - Find the part of components that is effected by the transformation
    - Transform this part to the original state (remove accent if the trans
    is ADD_ACCENT action, remove mark if the trans is ADD_MARK action)
    """
    action, factor = get_action (trans)
    comps = list(components)
    string = utils.join(comps)

    if action == Action.ADD_CHAR and string[-1] == trans[1]:
        if comps[2]: i = 2
        elif comps[1] : i = 1
        else: i = 0
        comps[i] = comps[i][:-1]
    elif action == Action.ADD_ACCENT:
        comps = accent.add_accent(comps, Accent.NONE)
    elif action == Action.ADD_MARK:
        if factor == Mark.BAR:
            comps[0] = comps[0][:-1] + \
                mark.add_mark_char(comps[0][-1:], Mark.NONE)
        else:
            if mark.is_valid_mark(comps, trans):
                comps[1] = u"".join([mark.add_mark_char(c, Mark.NONE)
                                          for c in comps[1]])
    return comps
Example #25
0
    def visit(self, node, scope):
        if_inferred = node.ifexpr.inferenced_type
        self.visit(node.ifexpr, scope)
        ifexpr_type = self.update_type(node.ifexpr.inferenced_type)
        bool_type = self.context.get_type("Bool")
        if isinstance(ifexpr_type, AutoType):
            ifexpr_type.set_upper_limmit([bool_type])
        node.ifexpr.inferenced_type = self.compare_types(
            if_inferred, ifexpr_type)

        self.visit(node.thenexpr, scope)
        then_type = self.update_type(node.thenexpr.inferenced_type)

        self.visit(node.elseexpr, scope)
        else_type = self.update_type(node.elseexpr.inferenced_type)

        node_inferred = node.inferenced_type

        joined = join(then_type, else_type)
        if not isinstance(joined, ErrorType):
            type_sets, heads = joined
            auto = AutoType("IF", heads, type_sets)
        else:
            auto = ErrorType()

        if is_subset(auto, node_inferred):
            node.inferenced_type = self.compare_types(node_inferred, auto)
Example #26
0
 def save_poster(self):
     thumbnail_dest = utils.join(self.nfo_path, 'folder.jpg')
     try:
         utils.copy(xbmc.translatePath(self.thumbnail), thumbnail_dest)
         log("save_poster: wrote: %s" % xbmc.translatePath(thumbnail_dest))
     except:
         log("save_poster: failed to write: %s from: %s" %  \
                 (xbmc.translatePath(self.thumbnail), xbmc.translatePath(thumbnail_dest)))
Example #27
0
 def save_poster(self):
     thumbnail_dest = utils.join(self.nfo_path, 'folder.jpg')
     try:
         utils.copy(xbmc.translatePath(self.thumbnail), thumbnail_dest)
         log("save_poster: wrote: %s" %  xbmc.translatePath(thumbnail_dest))
     except:
         log("save_poster: failed to write: %s from: %s" %  \
                 (xbmc.translatePath(self.thumbnail), xbmc.translatePath(thumbnail_dest)))
Example #28
0
def update_ursi_info(basedir, func_log):
    # I hard code the base dir here
    secret_dir = prepare_home_dir()
    scriptdir = utils.join(basedir, 'rocket', 'lib', 'scripts')
    ppi_script = prepare_script_path(func_log, scriptdir)
    print(scriptdir)
    # This will ask the ursi data manager to update things
    ursi_data_manager = UrsiDataManager(secret_dir_path=secret_dir, first_time_enter=True, ppiscript=ppi_script,
                                        PPIfilename="coinsPersonal.tmp")
Example #29
0
 def __init__(self, info, strm_path_movie, save_nfo_type, save_poster, save_fanart, nzbname, nzb):
     self.info = info
     self.strm_path_movie = strm_path_movie
     self.strm_path = utils.join(self.strm_path_movie, os.path.join(nzbname, ''))
     self.save_nfo_type = save_nfo_type
     self.save_poster = save_poster
     self.save_fanart = save_fanart
     self.nzbname = nzbname
     self.nzb = nzb
Example #30
0
def list_local(params):
    log("list_local: params: %s" % params)
    top_folder = utils.unquote_plus(params.get("folder"))
    type = utils.unquote_plus(params.get("type"))
    for folder in utils.listdir_dirs(top_folder):
        folder_path = utils.join(top_folder, folder)
        # Check if the folder contains a single nzb and no folders
        nzb_list = []
        folder_list = []
        for file in utils.listdir_files(folder_path):
            file_path = utils.join(folder_path, file)
            ext = os.path.splitext(file_path)[1]
            if ext == '.nzb' or ext == '.gz' or ext == '.zip':
                nzb_list.append(file_path)
        for sub_folder in utils.listdir_dirs(folder_path):
            folder_list.append(sub_folder)
        # If single nzb allow the folder to be playable and show info
        if len(nzb_list) == 1 and len(folder_list) == 0:
            # Fixing the naming of nzb according to SAB rules
            nzb_name = m_nzb.Nzbname(os.path.basename(nzb_list[0])).final_name
            if folder.lower() == nzb_name.lower():
                info = nfo.ReadNfoLabels(folder_path)
                info.info_labels['title'] = info.info_labels['title']
                url = "&nzbname=" + utils.quote_plus(nzb_name) +\
                      "&nzb=" + utils.quote_plus(nzb_list[0]) + "&type=" + type
                add_posts(info.info_labels, url, MODE_LOCAL_FILE_IN_DIR,
                          info.thumbnail, info.fanart, False)
            else:
                url = "&type=" + type + "&folder=" + utils.quote_plus(
                    folder_path)
                add_posts({'title': folder}, url, MODE_LOCAL_LIST, '', '')
        else:
            url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path)
            add_posts({'title': folder}, url, MODE_LOCAL_LIST, '', '')
    for file in utils.listdir_files(top_folder):
        ext = os.path.splitext(file)[1]
        if ext == '.nzb' or ext == '.gz' or ext == '.zip':
            file_path = utils.join(top_folder, file)
            url = "&nzbname=" + utils.quote_plus(m_nzb.Nzbname(file).final_name) +\
                  "&nzb=" + utils.quote_plus(file_path) + "&type=" + type
            add_posts({'title': file}, url, MODE_LOCAL_FILE, '', '', False)
    xbmcplugin.setContent(HANDLE, 'movies')
    xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True)
    return
Example #31
0
def login(path=None):
    """
    Login. Use  @authenticate decorator for a given path
    or call this function with a path to redirect to that path
    """
    if path is None:  # for @authenticate decorator
        path = request.get_cookie('validuserloginredirect', '/')

    print('PATH', path)

    # Check if already logged in and valled
    logged, session = check_logged_in()
    if logged:
        raw_input('logged')
        redirect(utils.join('/', path))  # SUCCESS!

    if request.method == 'GET':
        toptxt = "<p>Login:</p>"
        if request.query.get('failed', default='false').lower() == 'true':
            toptxt = "<p>Login Failed. Try again</p>"
        return '''{toptxt}
        <form action="/_login/{path}" method="post">
            Username: <input name="username" type="text" />
            Password: <input name="password" type="password" />
            <input value="Login" type="submit" />
        </form>
        '''.format(toptxt=toptxt, path=path)
    else:
        username = request.forms.get('username').lower()
        password = request.forms.get('password')
        print("USERS.get(username,'_')", USERS.get(username, '_'))
        if USERS.get(username, '_') == password:
            session['valid'] = True
            session['name'] = username
            session_manager.save(session)
            print('PASS', session, path)
            redirect(utils.join('/', path))  # SUCCESS!
        else:
            session['valid'] = False
            session_manager.save(session)
            print('FAIL', session)
            np = utils.join('/_login', path + '?failed=true')
            print('np', np)
            redirect(np)  # Fail!
Example #32
0
 def save(self):
     strm_path = utils.join(self.folder, ('%s.strm' % self.nzbname))
     nzb_path = utils.join(self.folder, ('%s.nzb' % self.nzbname))
     nzb = urllib.quote_plus(self.nzb)
     nzbname = urllib.quote_plus(self.nzbname)
     if utils.exists(strm_path):
         log("StrmFile: save: replacing .strm file: %s" %
             strm_path.encode("utf_8"))
     line = "plugin://plugin.program.pneumatic/?mode=strm&nzb=" + nzb +\
                    "&nzbname=" + nzbname
     try:
         utils.write(strm_path, line, 'wb')
     except:
         log("StrmFile: save: failed to create .strm file: %s" %
             strm_path.encode("utf_8"))
     if utils.exists(nzb_path):
         log("StrmFile: save: replacing .nzb file: %s" %
             nzb_path.encode("utf_8"))
     m_nzb.save(self.nzb, nzb_path)
Example #33
0
def list_local(params):
    log("list_local: params: %s" % params)
    top_folder = utils.unquote_plus(params.get("folder"))
    type = utils.unquote_plus(params.get("type"))
    for folder in utils.listdir_dirs(top_folder):
        folder_path = utils.join(top_folder, folder)
        # Check if the folder contains a single nzb and no folders
        nzb_list = []
        folder_list = []
        for file in utils.listdir_files(folder_path):
            file_path = utils.join(folder_path, file)
            ext = os.path.splitext(file_path)[1]
            if  ext == '.nzb' or ext == '.gz' or ext == '.zip':
                nzb_list.append(file_path)
        for sub_folder in utils.listdir_dirs(folder_path):
                folder_list.append(sub_folder)
        # If single nzb allow the folder to be playable and show info
        if len(nzb_list) == 1 and len(folder_list) == 0:
            # Fixing the naming of nzb according to SAB rules
            nzb_name = m_nzb.Nzbname(os.path.basename(nzb_list[0])).final_name
            if folder.lower() == nzb_name.lower():
                info = nfo.ReadNfoLabels(folder_path)
                info.info_labels['title'] = info.info_labels['title']
                url = "&nzbname=" + utils.quote_plus(nzb_name) +\
                      "&nzb=" + utils.quote_plus(nzb_list[0]) + "&type=" + type
                add_posts(info.info_labels, url, MODE_PLAY, info.thumbnail, info.fanart, False)
            else:
                url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path)
                add_posts({'title':folder}, url, MODE_LOCAL_LIST, '', '')
        else:
            url = "&type=" + type + "&folder=" + utils.quote_plus(folder_path)
            add_posts({'title':folder}, url, MODE_LOCAL_LIST, '', '')
    for file in utils.listdir_files(top_folder):
        ext = os.path.splitext(file)[1]
        if  ext == '.nzb' or ext == '.gz' or ext == '.zip':
            file_path = utils.join(top_folder, file)
            url = "&nzbname=" + utils.quote_plus(m_nzb.Nzbname(file).final_name) +\
                  "&nzb=" + utils.quote_plus(file_path) + "&type=" + type
            add_posts({'title':file}, url, MODE_PLAY, '', '', False)
    xbmcplugin.setContent(HANDLE, 'movies')
    xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True)
    return
Example #34
0
 def __init__(self, info, strm_path_movie, save_nfo_type, save_poster,
              save_fanart, nzbname, nzb):
     self.info = info
     self.strm_path_movie = strm_path_movie
     self.strm_path = utils.join(self.strm_path_movie,
                                 os.path.join(nzbname, ''))
     self.save_nfo_type = save_nfo_type
     self.save_poster = save_poster
     self.save_fanart = save_fanart
     self.nzbname = nzbname
     self.nzb = nzb
Example #35
0
 def save_fanart(self):
     cached_fanart = xbmc.getCacheThumbName(self.fanart).replace('.tbn', '')
     cached_fanart = "special://profile/Thumbnails/%s/%s.jpg" % (cached_fanart[0], cached_fanart)
     fanart_dest = utils.join(self.nfo_path, 'fanart.jpg')
     try:
         utils.copy(xbmc.translatePath(cached_fanart), xbmc.translatePath(fanart_dest))
         log("save_fanart: wrote: %s from: %s" % \
                 (xbmc.translatePath(fanart_dest), xbmc.translatePath(cached_fanart)))
     except:
         log("save_fanart: failed to write: %s from: %s" % \
                 (xbmc.translatePath(fanart_dest), xbmc.translatePath(cached_fanart)))
Example #36
0
def incomplete():
    log("incomplete:")
    active_nzbname_list = []
    m_nzbname_list = []
    m_row = []
    for folder in utils.listdir_dirs(INCOMPLETE_FOLDER):
        sab_nzo_id = SABNZBD.nzo_id(folder)
        if not sab_nzo_id:
            m_row.append(folder)
            m_row.append(None)
            m_nzbname_list.append(m_row)
            log("incomplete: m_nzbname_list.append: %s" % m_row)
            m_row = []
        else:
            m_row.append(folder)
            m_row.append(sab_nzo_id)
            active_nzbname_list.append(m_row)
            log("incomplete: active_nzbname_list: %s" % m_row)
            m_row = []
    nzbname_list = SABNZBD.nzo_id_history_list(m_nzbname_list)
    nzoid_history_list = [x[1] for x in nzbname_list if x[1] is not None]
    for row in active_nzbname_list:
        url = "&nzoid=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\
              "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\
              "&folder=" + utils.quote_plus(row[0])
        info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0]))
        info.info_labels['title'] = "Active - " + info.info_labels['title']
        add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart)
    for row in nzbname_list:
        if row[1]:
            url = "&nzoidhistory=" + str(row[1]) + "&nzbname=" + utils.quote_plus(row[0]) +\
                  "&nzoidhistory_list=" + utils.quote_plus(';'.join(nzoid_history_list)) +\
                  "&folder=" + utils.quote_plus(row[0])
            info = nfo.ReadNfoLabels(utils.join(INCOMPLETE_FOLDER, row[0]))
            add_posts(info.info_labels, url, MODE_INCOMPLETE_LIST, info.thumbnail, info.fanart)
        else:
            # Clean out a failed SABnzbd folder removal
            utils.dir_exists(utils.join(INCOMPLETE_FOLDER, row[0]), None)
    xbmcplugin.setContent(HANDLE, 'movies')
    xbmcplugin.endOfDirectory(HANDLE, succeeded=True, cacheToDisc=True)
    return
Example #37
0
    def _concatenate(self, final_units):
        '''Given the final selected units, extract the audio samples as numpy 
        arrays and concatenate them with overlapping phones.
        Keyword Arguments:
        final_units -- a list of final units in the form (phone_type, utterance)
                       where phone type indicates monophone or monophone/
                       diphone/triphone and the utterance is the name of the utterance
                       in the data set
        '''
        unit_wavs = []
        join_phones = False
        for phone_type, utterance, unit_idx in final_units:
            #print((utterance, unit_idx))
            utterance_dirs = preprocess.get_utterance_dirs(utterance)
            if phone_type == 'phone':
                utt2alignments = self.utt2alignments
                alignments = [utt2alignments[utterance][unit_idx]]
            elif phone_type == 'mono_di_tri':
                utt2alignments = self.utt2mono_di_tri_alignments
                alignments = utt2alignments[utterance][unit_idx]

            _, utterance_wav = wavfile.read(
                str(self.data_dir / utterance_dirs / (utterance + '.wav')))

            phones = []
            for phone in alignments:
                phone_start = phone[0]
                phone_end = phone[1]
                phones.append(utterance_wav[phone_start:phone_end])

            if join_phones:
                unit_wavs[-1] = utils.join(unit_wavs[-1], phones[0])
                '''
                else:
                    unit_wavs[-1] = utils.cross_fade(unit_wavs[-1], phones[1])
                '''
                if len(phones) > 1:
                    unit_wavs += phones[1:]
            else:
                unit_wavs += phones

            if len(alignments) == 1:
                join_phones = False
            else:
                join_phones = True

            #print((unit_start, unit_end))

            #print(utterance_wav.shape)
            #print(unit_wav)
        #print(unit_wavs)
        concatenation = np.concatenate(unit_wavs)
        return concatenation
Example #38
0
	def save(self, i):
		# 우선 저장
		fpath = join(self.fdir, "{}-{}.{}".format(self.fname, i, self.fext))  # full path
		mkdir(self.fdir)
		torch.save(self.model.state_dict(), fpath)

		# 현재 폴더에 저장된 같은 종류의 모델 확인
		files, idxs = ls_model(self.fdir, self.fname, self.fext)

		# 저장이 max_to_keep 보다 많으면 가장 오래된것 삭제
		if self.max_to_keep < len(files):
			rm(files[0])
Example #39
0
def del_local_file_in_dir(params):
    log("del_local_file_in_dir: params: %s" % params)
    local_file = utils.unquote_plus(params.get("nzb"))
    local_path = os.path.dirname(local_file)
    if xbmcgui.Dialog().yesno("Pneumatic", "Delete:", "%s" % local_path):
        for file in utils.listdir_files(local_path):
            local_file_path = utils.join(local_path, file)
            log("del_local_file_in_dir: delete: %s" % local_file_path)
            utils.delete(local_file_path)
        log("del_local_file_in_dir: rmdir: %s" % local_path)
        utils.rmdir(local_path)
        xbmc.executebuiltin("Container.Refresh")
Example #40
0
def del_local_file_in_dir(params):
    log("del_local_file_in_dir: params: %s" % params)
    local_file = utils.unquote_plus(params.get("nzb"))
    local_path = os.path.dirname(local_file)
    if xbmcgui.Dialog().yesno("Pneumatic", "Delete:", "%s" % local_path):
        for file in utils.listdir_files(local_path):
            local_file_path = utils.join(local_path, file)
            log("del_local_file_in_dir: delete: %s" % local_file_path)
            utils.delete(local_file_path)
        log("del_local_file_in_dir: rmdir: %s" % local_path)
        utils.rmdir(local_path)
        xbmc.executebuiltin("Container.Refresh")
Example #41
0
 def __init__(self, nfo_path):
     self.nfo_path = nfo_path
     filename_movie = utils.join(self.nfo_path, ("movie.nfo"))
     filename_tvshow = utils.join(self.nfo_path, ("episode.nfo"))
     self.is_episode = False
     if utils.exists(filename_movie):
         filename = filename_movie
     elif utils.exists(filename_tvshow):
         filename = filename_tvshow
         self.is_episode = True
     try:
         out = parseString(utils.read(filename, "r"))
     except:
         log(("ReadNfoLabels: could not open: %s.nfo") % (xbmc.translatePath(self.nfo_path)))
         out = None
     if out:
         self.info_labels = self._get_info_labels(out)
     else:
         self.info_labels = {"title": os.path.basename(self.nfo_path)}
     self.thumbnail = utils.join(self.nfo_path, "folder.jpg")
     self.fanart = utils.join(self.nfo_path, "fanart.jpg")
Example #42
0
def other(path=''):
    """a test one with the other login type"""
    logged, session = check_logged_in()
    print('logged', logged)
    print('session', session)
    if not logged:
        redirect(utils.join('/_login/other', path))
        # NOTE: You need to set the redirect to /_login/<route>/ to work around
        # the forwarding

    name = session.get('name')
    return 'other {} {}'.format(name, path)
Example #43
0
 def __init__(self, nfo_path):
     self.nfo_path = nfo_path
     filename_movie = utils.join(self.nfo_path, ('movie.nfo'))
     filename_tvshow = utils.join(self.nfo_path, ('episode.nfo'))
     self.is_episode = False
     if utils.exists(filename_movie):
         filename = filename_movie
     elif utils.exists(filename_tvshow):
         filename = filename_tvshow
         self.is_episode = True
     try:
         out = parseString(utils.read(filename, 'r'))
     except:
         log(("ReadNfoLabels: could not open: %s.nfo") % \
                 (xbmc.translatePath(self.nfo_path)))
         out = None
     if out:
         self.info_labels = self._get_info_labels(out)
     else:
         self.info_labels = {'title': os.path.basename(self.nfo_path)}
     self.thumbnail = utils.join(self.nfo_path, 'folder.jpg')
     self.fanart = utils.join(self.nfo_path, 'fanart.jpg')
Example #44
0
 def save_fanart(self):
     cached_fanart = xbmc.getCacheThumbName(self.fanart).replace('.tbn', '')
     cached_fanart = "special://profile/Thumbnails/%s/%s.jpg" % (
         cached_fanart[0], cached_fanart)
     fanart_dest = utils.join(self.nfo_path, 'fanart.jpg')
     try:
         utils.copy(xbmc.translatePath(cached_fanart),
                    xbmc.translatePath(fanart_dest))
         log("save_fanart: wrote: %s from: %s" % \
                 (xbmc.translatePath(fanart_dest), xbmc.translatePath(cached_fanart)))
     except:
         log("save_fanart: failed to write: %s from: %s" % \
                 (xbmc.translatePath(fanart_dest), xbmc.translatePath(cached_fanart)))
 def generate_symlinks(self):
     for (path, subdirs, files) in os.walk(self.indir):
         subdirs.sort()
         files.sort()
         for fname in files:
             dt = dateutil.parser.parse(fname.split('.')[0])
             sidtime = get_sidereal_time(dt)
             self.symlink(
                 os.path.abspath(os.path.realpath(os.path.join(path,fname))),
                 join(self.outdir,
                     str(sidtime.seconds/3600).zfill(2),
                     str((sidtime.seconds/60)%60).zfill(2),
                     fname))
Example #46
0
def strm_init(params):
    log("strm_init: params: %s" % params)
    strm_path = unicode(xbmc.getInfoLabel("ListItem.FileNameAndPath"), 'utf-8')
    log("strm_init: strm_path: %s" % strm_path)
    strm_base = os.path.dirname(strm_path)
    nzbname = params['nzbname']
    extensions = ['nzb', 'zip', 'gz']
    for ext in extensions:
        nzbname_ext = "%s.%s" % (utils.join(strm_base, nzbname), ext)
        if utils.exists(nzbname_ext):
            log("strm_init: exists: %s" % nzbname_ext)
            params['nzb'] = nzbname_ext
            params['type'] = 'add_file'
    return params
Example #47
0
def insertAtAllLocs(digLocs, digits, prime):
    """Insert the mutated prime into the map as a new set, if it's not already a key,
    or append to the existing set if it is
    """
    for locs in digLocs:
        # all subsets of mutable locations
        mutableNum = copy.copy(digits)
        for l in locs:
            mutableNum[l] = "*"
        mutatedNum = utils.join(mutableNum, True)
        if mutatedNum in P_MUTATED_MAP:
            P_MUTATED_MAP[mutatedNum].add(prime)
        else:
            P_MUTATED_MAP[mutatedNum] = set([prime])
Example #48
0
def prepare_script_path(func_log, scriptdir):
    get_ppi_script_ext = None
    if utils.systemName in ('Linux', 'Darwin'):  # use the
        get_ppi_script_ext = '.sh'
    elif utils.systemName in ('Windows'):  #
        get_ppi_script_ext = '.bat'
    else:
        func_log.critical('This platform is not supported!')
        utils.exit()

    ppi_script_filename = 'list_gender_birth_guid' + get_ppi_script_ext
    ppi_script_path = utils.join(scriptdir, ppi_script_filename)
    func_log.info('ppi script is %s' % ppi_script_path)
    return ppi_script_path
Example #49
0
 def save(self, type="movie", filename="movie.nfo"):
     """Saves XBMC .nfo xml data.
     
     type is a string of 'movie' or 'tvshow' or 'episodedetails'
     """
     filepath = utils.join(self.nfo_path, filename)
     if self.is_mini and type == "movie" and "code" in self.info_labels:
         doc = "http://www.imdb.com/title/%s" % self.info_labels["code"]
         self.write_doc(filepath, doc)
     if self.is_mini and type == "tvshow" and "tvdb-show" in self.info_labels:
         doc = "http://thetvdb.com/index.php?tab=series&id=%s" % self.info_labels["tvdb-show"]
         self.write_doc(filepath, doc)
     else:
         self.write_doc(filepath, self.to_xml(type))
Example #50
0
 def save(self, type = 'movie', filename = 'movie.nfo'):
     """Saves XBMC .nfo xml data.
     
     type is a string of 'movie' or 'tvshow' or 'episodedetails'
     """
     filepath = utils.join(self.nfo_path, filename)
     if self.is_mini and type == 'movie' and 'code' in self.info_labels:
         doc = 'http://www.imdb.com/title/%s' % self.info_labels['code']
         self.write_doc(filepath, doc)
     if self.is_mini and type == 'tvshow' and 'tvdb-show' in self.info_labels:
         doc = 'http://thetvdb.com/index.php?tab=series&id=%s' % self.info_labels['tvdb-show']
         self.write_doc(filepath, doc)
     else:
         self.write_doc(filepath, self.to_xml(type))
 def generate_symlinks(self):
     for (path, subdirs, files) in os.walk(self.indir):
         subdirs.sort()
         files.sort()
         for name in files:
             if not name.endswith('.fits'):
                 continue
             fname = os.path.join(path, name)
             hdulist = pyfits.open(fname, do_not_scale_image_data=True)
             hdu = hdulist[0] 
             date_obs = hdu.header['DATE-OBS'] 
             self.symlink(os.path.abspath(fname),
                 join(self.outdir,
                     new_path_from_datestamp(date_obs),
                     date_obs+'.fits'))
Example #52
0
def is_valid_mark(comps, mark_trans):
    """
    Check whether the mark given by mark_trans is valid to add to the components
    """
    components = list(comps)
    if components[1] != u"":
        raw_vowel = accent.add_accent(components, Accent.NONE)[1].lower()
        raw_vowel = utils.join([add_mark_char(c, Mark.NONE) for c in raw_vowel])
    if mark_trans[0] == 'd' and components[0] \
            and components[0][-1].lower() in (u"d", u"đ"):
        return True
    elif components[1] != u"" and raw_vowel.find(mark_trans[0]) != -1:
        return True
    else:
        return False
Example #53
0
import logging
from __init__ import secretdir,scriptdir
from loggers import func_log

PPIfilename = "coinsPersonal.tmp"
get_ppi_script_ext = None
if utils.systemName in ('Linux', 'Darwin'):  # use the
    get_ppi_script_ext = '.sh'
elif utils.systemName in ('Windows'):  #
    get_ppi_script_ext = '.bat'
else:
    func_log.critical('This platform is not supported!')
    utils.exit()

get_ppi_script_filename = 'list_gender_birth_guid' + get_ppi_script_ext
get_ppi_script_path = utils.join(scriptdir, get_ppi_script_filename)


class UrsiDataManager(object):
    def __init__(self, secret_dir_path, first_time_enter, PPIfilename, ppiscript = None, func_log = logging):
        self.first_time_enter = first_time_enter

        self.temp_file_path = path.join(secret_dir_path, PPIfilename)
        self.func_log = func_log
        self.data_list = []
        self.ppiscript = ppiscript

        # prepare the file. If it doesn't exist, prepare it. If it exists, no need for doing anything
        # Also check the empty of the file
        self.ensure_data_file_exist()
Example #54
0
 def png(self, path, data, image_filter=flatten_max(5000)):
     img = smp.toimage(image_filter(data))
     img.save(join(self.outdir, "png", path + ".png"))
Example #55
0
assoc_Name_Type_Map = aMapper.mapAssocTypeNameID()

prop_Name_ID_Map = propMapper.mapPropNameID()		# (prop name, prop id)
prop_ID_Name_Map = propMapper.mapPropIDName()		# (prop id, prop name)
prop_Name_Alias_Map = propMapper.mapPropNameAlias()	# (propName, propAlias)
prop_Alias_Name_Map = propMapper.mapPropAliasName()	# (propAlias, propName)
prop_Alias_ID_Map = propMapper.mapPropAliasID()		# (propAlias, propID) - e.g. ('insert_type', '48')

prop_Category_Name_ID_Map = propMapper.mapPropCategoryNameID()

featureNameColorMap = propMapper.mapFeatureNameColor()

#print `featureNameColorMap`

# Get enzymes list for mapping sequence features
enzDict = utils.join(sHandler.sitesDict, sHandler.gatewayDict)
enzDict = utils.join(enzDict, sHandler.recombDict)	# add LoxP
enzDict['None'] = ""					# add 'None'

# currUser is an INT user ID
def getCurrentUserProjects(currUser):
	
	#print "Content-type:text/html"
	#print
	
	# get projects user has AT LEAST Read access to (i.e. if he is explicitly declared a Writer on a project but not declared a Reader, that's allowed)
	currReadProj = packetHandler.findMemberProjects(currUser, 'Reader')
	currWriteProj = packetHandler.findMemberProjects(currUser, 'Writer')
	publicProj = packetHandler.findAllProjects(isPrivate="FALSE")
	
	# list of Packet OBJECTS
def process_key(string, key, case = 0, config = DefaultConfig()):
    """
    Process the given string and key based on the given input method and
    config.
    
    Args:
        string -
        key -
        case (optional) - Force the output's case. Mostly to determine 
            the case of TELEX's [, ] keys. 0: lower, 1: upper. Default: 0.
        im (optional) - one of 'telex', 'simple-telex', 'vni'.
            Default: 'telex'.
        config - a dictionary.
    """
    ## BEGIN TRICKS (scroll down please)
    im = config.input_method
    # People can sometimes be really mischievous :<
    if im in IMs:
        im = IMs[im]
    else:
        im = IMs['telex']

    # Handle non-alpha string like 'tôi_là_ai' by putting 'tôi_là_' in 
    # the `garbage` variable, effectively skipping it then put it back 
    # later.
    # TODO Should this be the ibus engine's job?
    garbage = u''
    for i in range(-1, -len(string)-1, -1): # Reverse indices [-1, -2, -3, ...]
        if not string[i].isalpha():
            garbage += string[:i] + string[i]
            string = u'' + string[i+1:] if i != -1 else u''
            break
    
    # Handle process_key('â', '_')
    if not key in im and not key.isalpha():
        string += key
        return garbage + string
    
    ## END TRICKS (here comes real code)
    
    # Try to break the string down to 3 components
    # separate('chuyen') = ['ch', 'uye', 'n']
    comps = separate(string)
    
    # Refuse to process things like process('zzam', 'f')
    if comps == None:
        return None
    
    # Apply transformations
    trans_list = get_transformation_list(key, im, case = case);
    new_comps = comps

    for trans in trans_list:
        new_comps = transform(new_comps, trans)

    # Double typing an IM key to undo.
    # Eg: process_key(u'à', 'f')
    #  -> transform(['', u'à', ''], '\\') = ['', 'à', '']
    #  -> reverse(u'à', '\\') = 'a'
    #
    # Note that when undo 'ư' with 'w', this function will always return
    # 'uw' because of lack of raw string information. It is up to the
    # user of this module to change the returned value to 'w' when necessary.
    # 
    if new_comps == comps:
        for trans in trans_list:
            new_comps = reverse(new_comps, trans)
            tmp = list(new_comps)
            if tmp != comps:
                new_comps = utils.append_comps(new_comps, unicode(key))
                return garbage + utils.join(new_comps)
        new_comps = utils.append_comps(new_comps, unicode(key))
        
    # One last check to rule out cases like 'ảch' or 'chuyểnl'
    if not is_valid_combination(new_comps):
        return None
    return garbage + utils.join(new_comps)
Example #57
0
 def __init__(self, strm_path):
     self.cache_path = utils.join(strm_path, 'rageid.cache')
     if not utils.exists(self.cache_path):
         pickle.dump( dict(), open( self.cache_path, "wb" ) )
Example #58
0
def remove_accent_string(string):
    """
    Remove all accent from a whole string.
    """
    return utils.join([add_accent_char(c, Accent.NONE) for c in string])
Example #59
0
def pre_play(nzbname, **kwargs):
    log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs))
    mode = kwargs.get('mode', None)
    sab_nzo_id = kwargs.get('nzo', None)
    iscanceled = False
    folder = utils.join(INCOMPLETE_FOLDER, nzbname)
    folder_one = folder + '.1'
    if utils.exists(folder_one):
        folder = folder_one
    sab_file_list = []
    multi_arch_list = []
    if sab_nzo_id is None:
        sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname)
        nzf_list = utils.dir_to_nzf_list(folder, sabnzbd)
    else:
        nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id)
        nzf_list = nzo.nzf_list()
        sab_nzo_id_history = None
    sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list)
    # TODO
    # If we cant find any rars in the queue, we have to wait for SAB
    # and then guess the names...
    # if len(nzf_list) == 0:
        # iscanceled = get_nzf(folder, sab_nzo_id, None)
    is_movie_in_rar = True
    if len(sorted_rar_nzf_list) == 0:
        # look for other playable files
        multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list)
        if len(multi_nzf_list) > 0:
            is_movie_in_rar = False
    else:
        multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list)
        sorted_nzf_list = sorted_rar_nzf_list
        clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list)
    if len(multi_nzf_list) > 0:
        # Loop though all multi archives and add file to the 
        play_list = []
        for nzf in multi_nzf_list:
            if sab_nzo_id is not None:
                response = set_streaming(sab_nzo_id)
                log("pre_play: set_streaming: %s" % response)
                t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,))
                t.start()
                iscanceled = get_nzf(folder, sab_nzo_id, nzf)
            if iscanceled:
                break
            else:
                if is_movie_in_rar:
                    # RAR ANALYSYS #
                    in_rar_file_list = utils.rar_filenames(folder, nzf.filename)
                    movie_list = utils.sort_filename(in_rar_file_list)
                    log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list))
                else:
                    movie_list = [os.path.join(folder, nzf.filename)]
                # Make sure we have a movie
                if not (len(movie_list) >= 1):
                    utils.notification("Not a movie!")
                    log("pre_play: no movie in movie_list")
                    break
                # Who needs sample?
                movie_no_sample_list = utils.no_sample_list(movie_list)
                # If auto play is enabled we skip samples in the play_list
                if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST:
                    for movie_file in movie_no_sample_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                else:
                    for movie_file in movie_list:
                        play_list.append(nzf.filename)
                        play_list.append(movie_file)
                # If the movie is a .mkv or .mp4 we need the last rar
                if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar:
                    # If we have a sample or other file, the second rar is also needed..
                    if len(in_rar_file_list) > 1:
                        second_nzf = clean_sorted_nzf_list[1]
                        iscanceled = get_nzf(folder, sab_nzo_id, second_nzf)
                    last_nzf = clean_sorted_nzf_list[-1]
                    iscanceled =  get_nzf(folder, sab_nzo_id, last_nzf)
                    if iscanceled: 
                        break 
        if iscanceled:
            log("pre_play: get_nzf: canceled")
            return
        else:
            rar_file_list = [x.filename for x in sorted_nzf_list]
            if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1):
                if AUTO_PLAY and ( mode is None or mode is MODE_STRM):
                    video_params = dict()
                    if not mode:
                        video_params['mode'] = MODE_AUTO_PLAY
                    else:
                        video_params['mode'] = MODE_STRM
                    video_params['play_list'] = utils.quote_plus(';'.join(play_list))
                    video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list))
                    video_params['folder'] = utils.quote_plus(folder)
                    return play_video(video_params)   
                else:
                    return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history)
            else:
                utils.notification("No rar\'s in the NZB!")
                log("pre_play: no rar\'s in the NZB")
                return
    else:
        utils.notification("No playable files found!")
        log("pre_play: no playable files found")
        return
Example #60
0
def is_nzb_home(params):
    log("is_nzb_home: params: %s" % params)
    get = params.get
    nzb = utils.unquote_plus(get("nzb"))
    nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name
    folder = utils.join(INCOMPLETE_FOLDER, nzbname)
    iscanceled = False
    type = get('type', 'addurl')
    sab_nzo_id = SABNZBD.nzo_id(nzbname, nzb)
    log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id))
    if not utils.dir_exists(folder, sab_nzo_id):
        progressDialog = xbmcgui.DialogProgress()
        progressDialog.create('Pneumatic', 'Sending request to SABnzbd')
        category = get_category()
        if type == 'addurl':
            type, nzb = nzb_cache(type, nzb, nzbname)
        # SABnzbd and URI should be latin-1 encoded
        if type == 'addurl':
            response = SABNZBD.addurl(nzb.encode('latin-1'), nzbname, category=category)
        elif type == 'add_local':
            response = SABNZBD.add_local(nzb.encode('latin-1'), category=category)
        elif type == 'add_file':
            response = SABNZBD.add_file(nzb.encode('latin-1'), category=category)
        log("is_nzb_home: type: %s response: %s" %(type, response))
        if "ok" in response:
            progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download')
            seconds = 0
            #SABnzbd uses nzb url as name until it has downloaded the nzb file
            sab_nzo_id_init = SABNZBD.nzo_id(nzbname, nzb)
            log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init)
            while not (sab_nzo_id and utils.exists(folder)):
                sab_nzo_id = SABNZBD.nzo_id(nzbname)
                label = str(seconds) + " seconds"
                log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label))
                progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label)
                if progressDialog.iscanceled():
                    progressDialog.close()
                    log("is_nzb_home: waiting for nzb: canceled")
                    # Fix for hang when playing .strm
                    time.sleep(1)
                    xbmc.Player().stop()
                    if sab_nzo_id is None and sab_nzo_id_init is not None:
                        sab_nzo_id = sab_nzo_id_init
                    #Trying to delete both the queue and history
                    if sab_nzo_id is not None:
                        pause = SABNZBD.pause_queue(id=sab_nzo_id)
                        log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause))
                        time.sleep(3)
                        delete_msg = SABNZBD.delete_queue('',sab_nzo_id)
                        log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                        if not "ok" in delete_msg:
                            delete_msg = SABNZBD.delete_history('',sab_nzo_id)
                            log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg))
                    else:
                        log("is_nzb_home: failed removing %s from the queue" % nzbname)
                    iscanceled = True
                    break
                time.sleep(1)
                seconds += 1
            if not iscanceled:
                switch = SABNZBD.switch(0, '', sab_nzo_id)
                log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
                if not "ok" in switch:
                    progressDialog.update(0, 'Failed to prioritize the nzb!')
                    time.sleep(1)
                # Dont add meta data for local nzb's
                if type == 'addurl':
                    t = Thread(target=save_nfo, args=(folder,))
                    t.start()
                progressDialog.close()
                return True, sab_nzo_id
            else:
                progressDialog.close()
                return False, sab_nzo_id
        else:
            progressDialog.close()
            log("is_nzb_home: failed adding nzb to SAB")
            # Fix for hang when playing .strm
            xbmc.Player().stop()            
            utils.notification("Request to SABnzbd failed!")
            return False, sab_nzo_id
    else:
        switch = SABNZBD.switch(0,'' , sab_nzo_id)
        log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch))
        if not "ok" in switch:
            utils.notification("Failed to prioritize the nzb!")
        # TODO make sure there is also a NZB in the queue
        return True, sab_nzo_id