コード例 #1
0
def demo():
    packer = Packer(256,512)  # or:  new GrowingPacker();
    files=getfiles.getfiles()
    nodes=[]
    for f in files:
        im=Image.open(f)
        node=Node(im.size[0],im.size[1])
        node.filename=f
        nodes.append(node)
    nodes=sorted(nodes,key=functools.cmp_to_key(comp))
    packer.fit(nodes);
    im=Image.new("RGBA",(packer.root.w,packer.root.h))
    for n in range(len(nodes)):
        block = nodes[n];
        if (block.fit!=None):
          print(n,block.fit.x, block.fit.y, block.w, block.h,block.fit.used,block.filename,block.rotate)
          im1=Image.open(block.filename)
          if block.rotate==True:
            im1=im1.rotate(-90)
          im.paste(im1,(block.fit.x, block.fit.y))
        else:
          print(n,block.x, block.y, block.w, block.h,block.used,block.filename,block.rotate)
    print(packer.root.w,packer.root.h)
    im.save("output.png")
    return(packer,nodes)
コード例 #2
0
 def getcommandsfiles(self):
     """return a list of commands files"""
     result = []
     files = getfiles.getfiles(os.getcwd())
     for f in files:
         if os.path.splitext(
                 f)[1] == ".py" and os.path.basename(f)[0] != "_":
             if os.path.dirname(f).split(
                     os.sep)[-2:] == ["management", "commands"]:
                 result.append(f)
     return result
コード例 #3
0
 def update_resources(self):
     f = os.path.join(self.path, "resources.txt")
     if not os.path.exists(f):
         print("SKIP: %s NOT EXISTS" % f)
     resources = list(filter(None, open(f).read().splitlines()))
     files = getfiles.getfiles(self.path)
     matches = ["demo.details", "fiddle.manifest"]
     for f in filter(lambda f: os.path.basename(f) in matches, files):
         if os.path.exists(f):
             data = yaml.load(open(f, 'r'))
             if data.get("resources", []) != resources:
                 data["resources"] = resources
                 yaml.dump(data, open(f, 'w'), default_flow_style=False)
コード例 #4
0
ファイル: frep.py プロジェクト: rmccampbell/PythonProjects
def frep(pattern, replace, *files, inplace=False, fixed=False):
    if inplace:
        mode = "r+"
    else:
        mode = "r"
        out = sys.stdout
    if fixed:
        pattern = re.escape(pattern)
    files = getfiles.getfiles(files, mode, default="-")

    try:
        for file in files:
            if inplace:
                lines = file.readlines()
                file.seek(0)
                file.truncate()
                out = file
            else:
                lines = file

            for line in lines:
                out.write(re.sub(pattern, replace, line))
    except ValueError:
        raise ValueError("cannot use inplace on stdin")
コード例 #5
0
 def create_readme(self):
     files = getfiles.getfiles(self.path)
     matches = ["demo.html", "fiddle.html"]
     for f in filter(lambda f: os.path.basename(f) in matches, files):
         _readme(os.path.dirname(f))
コード例 #6
0
 def build_html(self):
     files = getfiles.getfiles(self.path)
     matches = ["demo.html", "fiddle.html"]
     for f in filter(lambda f: os.path.basename(f) in matches, files):
         _build(os.path.dirname(f))
コード例 #7
0
ファイル: pygrep.py プロジェクト: rmccampbell/PythonProjects
def grep(pattern, *files, **kwargs):
    if isinstance(pattern, argparse.Namespace):
        args = pattern
        pattern = args.pattern
        files = args.files
    else:
        kwargs2 = DEF_KWARGS.copy()
        kwargs2.update(kwargs)
        args = argparse.Namespace(pattern=pattern, files=files, **kwargs2)

    files = getfiles.getfiles(files)
    flags = args.ignore_case and re.IGNORECASE

    if args.fixed:
        pattern = re.escape(pattern)
    if args.line:
        pattern = r'^' + pattern + r'$'
    if args.word:
        pattern = r'\b' + pattern + r'\b'

    pattern = re.compile(pattern, flags)

    before = after = args.context
    if args.before_context is not None:
        before = args.before_context
    if args.after_context is not None:
        after = args.after_context
    before_buff = collections.deque(maxlen=before)

    if args.match_files or args.no_match_files:
        args.count, args.with_filename = False, False

    stdout = getfiles.set_encoding()

    for file in files:
        if args.count:
            count = 0

        print_filename = args.with_filename
        before_buff.clear()
        after_limit = 0

        for lno, line in enumerate(file):
            match = pattern.search(line)
            if args.only_match:
                matches = pattern.finditer(line)
            if (match and not args.invert) or (not match and args.invert):
                if args.match_files:
                    print(file.name)
                    break
                if args.no_match_files:
                    break

                if print_filename:
                    print('\n-- {} --'.format(file.name))
                    print_filename = False

                if args.count:
                    count += 1
                    continue

                print(''.join(before_buff), end='')
                before_buff.clear()

                prefix = '{:3}:'.format(lno) if args.line_number else ''

                if args.only_match:
                    print('\n'.join(prefix + m.group() for m in matches))
                else:
                    print(prefix + line, end='')

                after_limit = after

            elif after_limit:
                if args.line_number:
                    line = '{:3}-{}'.format(lno, line)
                print(line, end='')
                after_limit -= 1

            else:
                if args.line_number:
                    line = '{:3}-{}'.format(lno, line)
                before_buff.append(line)

        else:
            if args.no_match_files: print(file.name)

        if args.count:
            print(count)

    getfiles.reset_encoding(stdout)