Ejemplo n.º 1
0
def clean(rep="."):
    """Thorough cleaning of all arborescence rooting at rep.

    Args:
        rep: (str) root directory to start the walk

    Returns:
        None
    """
    for name in ("build", "dist"):
        pth = pj(rep, name)
        if exists(pth):
            rmtree(pth)

    for root, dnames, fnames in walk(rep):
        # do not walk directories starting with "."
        for name in tuple(dnames):
            if "clean.no" in listdir(pj(root, name)):
                dnames.remove(name)
            elif name.startswith("."):
                dnames.remove(name)
            elif name == "__pycache__":
                rmtree(pj(root, name))
                dnames.remove(name)

        for name in fnames:
            if not name.startswith("."):
                if splitext(name)[1] in [".pyc", ".pyo"]:
                    remove(pj(root, name))
Ejemplo n.º 2
0
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)

    # create extra dirs
    for pth in ("data", "data/sessions", "../see_repo"):
        if not os.path.exists(pth):
            os.mkdir(pth)

    # remove sqlite file
    sqlite_pth = "data/seeweb.sqlite"
    if os.path.exists(sqlite_pth):
        os.remove(sqlite_pth)

    # clean data
    for obj_type in ("ro", "team", "user"):
        for name in glob("seeweb/data/avatar/%s/*.png" % obj_type):
            try:
                os.remove(name)
            except OSError:
                print "unable to remove %s" % name

    for name in glob("seeweb/data/gallery/*/"):
        try:
            rmtree(name)
        except OSError:
            print "unable to remove %s" % name

    for name in glob("../see_repo/*/"):
        try:
            rmtree(name)
        except OSError:
            print "unable to remove %s" % name

    # setup config
    config_uri = argv[1]
    options = parse_vars(argv[2:])

    setup_logging(config_uri)
    settings = get_appsettings(config_uri, options=options)

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    # populate database
    with transaction.manager:
        session = DBSession()

        init_users.main(session)
        init_sample.main(session)

        pjt_auth_managment.main(session, users[0], containers[0])
        pjt_data.main(session, users[0], containers[0])
        pjt_workflow.main(session, users[0], containers[0])
Ejemplo n.º 3
0
    def delete_gallery(project):
        """Remove all images from gallery.

        Args:
            project: (Project)

        Returns:
            (None)
        """
        gal_dir = GalleryItem.gallery_pth(project.id)
        if exists(gal_dir):
            rmtree(gal_dir)
Ejemplo n.º 4
0
def view(request):
    if request.unauthenticated_userid is None:
        msg = "Operation non authorized for anonymous users"
        request.session.flash(msg, 'warning')
        return HTTPFound(location=request.route_url("home"))

    if "new_ro" in request.params:
        session = DBSession()
        uid = request.params["ro_id"]
        created = parse(request.params["created"])
        name = request.params["name"]
        ro_type = request.params["ro_type"]

        # do some checking
        assert len(uid) == 32

        print uid, created, name, ro_type, "\n" * 10

        # gather data
        data = dict(id=uid,
                    owner=request.unauthenticated_userid,
                    created=created,
                    name=name,
                    version=0)

        # create RO
        ro = register(session, ro_type, data)
        return HTTPFound(location=request.route_url("ro_view_home", uid=ro.id))
    elif "submit_upload" in request.params:
        field_storage = request.params["upload_file"]
        if field_storage == "":
            msg = "Need to select file first"
            request.session.flash(msg, 'warning')
        else:
            pth = upload_file(field_storage)
            session = DBSession()
            ro = create_from_file(session, pth, request.unauthenticated_userid)
            rmtree(dirname(pth))

            if ro is None:
                msg = "Unable to find a valid RO in this file"
                request.session.flash(msg, 'warning')
            else:
                return HTTPFound(location=request.route_url("ro_view_home", uid=ro.id))

    uid = uuid1().hex
    created = datetime.now()

    ro_types = ["container", "data", "ro", "article"]

    return dict(uid=uid, created=created, ro_types=ro_types)