コード例 #1
0
ファイル: views_sites.py プロジェクト: Qbitus/pinecast
def new_site(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)

    if not payment_plans.minimum(
        UserSettings.get_from_user(pod.owner).plan,
        payment_plans.FEATURE_MIN_SITES):
        raise Http404()

    data = {
        'podcast': pod,
        'themes': Site.SITE_THEMES,
    }

    if not req.POST:
        return _pmrender(req, 'dashboard/sites/page_new.html', data)

    try:
        site = Site(
            podcast=pod,
            theme=req.POST.get('theme'),
            cover_image_url=signer.unsign(req.POST.get('cover-url')) if req.POST.get('cover-url') else None,
            logo_url=signer.unsign(req.POST.get('logo-url')) if req.POST.get('logo-url') else None,
            analytics_id=req.POST.get('analytics_id'),
            itunes_url=req.POST.get('itunes_url'),
            stitcher_url=req.POST.get('stitcher_url')
        )
        site.save()
    except Exception as e:
        print e
        data.update(error=True, default=req.POST)
        return _pmrender(req, 'dashboard/sites/page_new.html', data)
    else:
        return redirect('site_options', podcast_slug=podcast_slug)
コード例 #2
0
ファイル: action.py プロジェクト: qt-pay/devops-3
 def init_project(self, site: Site, project):
     commits = gl.get_commits(project)
     for commit in commits:
         Release(site=site, version=commit.id, message=commit.message, committed_time=commit.committed_date).save()
     gl.add_hook(project, "http://{}:{}{}".format(SERVER_NAME if SERVER_NAME else SERVER_IP, SERVER_PORT, reverse('hook-list')))
     site.status = 1
     site.save()
コード例 #3
0
def new_site(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)

    if not payment_plans.minimum(
            UserSettings.get_from_user(pod.owner).plan,
            payment_plans.FEATURE_MIN_SITES):
        raise Http404()

    try:
        site = Site(
            podcast=pod,
            theme=req.POST.get('theme'),
            cover_image_url=signer.unsign(req.POST.get('cover-url'))
            if req.POST.get('cover-url') else None,
            logo_url=signer.unsign(req.POST.get('logo-url'))
            if req.POST.get('logo-url') else None,
            analytics_id=req.POST.get('analytics_id'),
            itunes_url=req.POST.get('itunes_url'),
            stitcher_url=req.POST.get('stitcher_url'),
            show_itunes_banner=req.POST.get('show_itunes_banner') == 'true')
        site.save()
    except Exception as e:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) +
            '?error=true#site')
    else:
        return redirect(
            reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#site')
コード例 #4
0
ファイル: action.py プロジェクト: qt-pay/devops-3
 def webserver_offline(self, site: Site):
     # 暂时实现站点信息更新,后期实现站点下线
     if not site.webserver_set.filter(type=0).count() > 0:
         site.pre_version = None
     if not site.webserver_set.filter(type=1).count() > 0:
         site.online_version = None
     if not site.pre_version and not site.online_version:
         site.status = 1
     site.save()
コード例 #5
0
    def handle(self, *args, **options):
        csvfile = options['csvfile']
        reader = csv.DictReader(csvfile)

        # Wrap in a transaction so if creating any site fails, the database
        # will automatically rollback.
        with transaction.atomic():
            num_rows = 0
            for row in reader:
                new_site = Site(name=row['Organization Name'],
                                domain=row['Domain Name'])
                new_site.save()
                num_rows += 1
            print('Added {} sites from {}'.format(num_rows,
                                                  abspath(csvfile.name)))
コード例 #6
0
ファイル: Frontier.py プロジェクト: pajki/seminar_01
    def add_url(self, new_url, from_page=None, delay=4):
        """
        This function adds potentially new page to frontier and creates new empty page entry with code "FRONTIER"
        :param delay: number of second to delay crawler
        :param new_url: full url of potentially new page (string) to be added to frontier
        :type new_url: str
        :param from_page: page that url was found on
        :type from_page: Page
        :return: value that indicates whether url was added to frontier
        :rtype: bool
        """
        if Page.objects.filter(url=new_url).exists():
            return False

        netloc = urlparse(new_url).netloc

        # Create new site if it doesn't exist yet
        try:
            site = Site.objects.get(domain=netloc)
        except Site.DoesNotExist:
            # Download robots and sitemap
            sitemap_content, _ = self.http_downloader.get_sitemap_for_url(
                "http://" + netloc, True)
            robots_content, _ = self.http_downloader.get_robots_file(
                "http://" + netloc, True)
            # Save new site
            site = Site(domain=netloc,
                        sitemap_content=sitemap_content,
                        robots_content=robots_content)
            site.save()

        page_type = PageType.objects.get(code="FRONTIER")
        page = Page(url=new_url,
                    site=site,
                    page_type_code=page_type,
                    crawl_delay=delay)
        page.save()

        # Create link if valid from_page was given
        if from_page:
            try:
                link = Link(from_page=from_page, to_page=page)
                link.save()
            except ValueError:
                logger.error("from_page must be valid Page instance")

        self.queue.put(page)
        return True
コード例 #7
0
ファイル: action.py プロジェクト: qt-pay/devops-3
    def publish(self, oper: Oper, site: Site, server_type=0):
        try:
            # 判断本地代码文件是否存在(不存在则拉取文件)
            path = '{}/{}/{}.tar.gz'.format(CODE_DIR, site.project, oper.oper_version.version)
            p = Path(path)
            if not p.is_file():
                if not p.parent.is_dir():
                    p.parent.mkdir(parents=True, exist_ok=True)

                with open(path, 'wb') as f:
                    f.write(gl.pull_archive(gl.get_project(site.project), oper.oper_version.version))

            # 远程服务器代码保存路径
            dest = "{0}/{1}/{1}-{2}-{3}".format(site.dev_path, site.project, oper.oper_version.version[:8], oper.oper_version.version)

            fbs = set()

            # 过滤指定环境的服务器
            webservers = site.webserver_set.filter(type=server_type).all()
            for webserver in webservers:
                server = webserver.server
                fb = FabricApi(server.ip, server.deploy_user, server.deploy_pwd)
                # 判断代码文件是否存在(不存在则发送文件)
                fb.send_file(path, dest)
                fbs.add(fb)

            #
            for fb in fbs:
                fb.update_symbolic_link(site.site_path, dest)

            oper.oper_status += 1

            if oper.oper_status == 1:
                site.pre_version = oper.oper_version
            else:
                site.pre_version = None
                site.online_version = oper.oper_version
                site.status = 2
                site.deploy_status = False

            oper.deploy_status = 0
            oper.save()
            site.save()
        except:
            self.rollback(oper, site, False if server_type else True)
コード例 #8
0
ファイル: test_data.py プロジェクト: jctt1983/djangoAggr
    def generate_test_data(self):
        sid = transaction.savepoint()
        try:
            for n in xrange(1, 21):
                s = Site(name='Site %s' % n)
                s.save()

                for m in xrange(100):
                    v1 = decimal.Decimal(random.randrange(100, 100000)) / 100
                    v2 = decimal.Decimal(random.randrange(100, 100000)) / 100
                    d = SiteData(site=s, date=date.today(), dataA=v1, dataB=v2)
                    d.save()

                msg = 'Successfully created site "%s"' % s.id
                self.stdout.write(self.style.SUCCESS(msg))
            transaction.savepoint_commit(sid)
        except Exception as e:
            transaction.savepoint_rollback(sid)
            msg = 'Failed to complete this process: ' + str(e)
            self.stdout.write(self.style.ERROR(msg))
コード例 #9
0
ファイル: views_sites.py プロジェクト: Pinecast/pinecast
def new_site(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)

    if not payment_plans.minimum(
        UserSettings.get_from_user(pod.owner).plan,
        payment_plans.FEATURE_MIN_SITES):
        raise Http404()

    try:
        site = Site(
            podcast=pod,
            theme=req.POST.get('theme'),
            cover_image_url=signer.unsign(req.POST.get('cover-url')) if req.POST.get('cover-url') else None,
            logo_url=signer.unsign(req.POST.get('logo-url')) if req.POST.get('logo-url') else None,
            analytics_id=req.POST.get('analytics_id'),
            itunes_url=req.POST.get('itunes_url'),
            stitcher_url=req.POST.get('stitcher_url'),
            show_itunes_banner=req.POST.get('show_itunes_banner') == 'true')
        site.save()
    except Exception as e:
        return redirect(reverse('podcast_dashboard', podcast_slug=podcast_slug) + '?error=true#site')
    else:
        return redirect(reverse('podcast_dashboard', podcast_slug=podcast_slug) + '#site')
コード例 #10
0
ファイル: action.py プロジェクト: qt-pay/devops-3
    def rollback(self, oper: Oper, site: Site, all=False):
        try:
            dest = "{0}/{1}/{1}-{2}-{3}".format(site.dev_path, site.project, oper.online_version.version[:8], oper.online_version.version)

            webservers = site.webserver_set
            if not all:
                webservers = webservers.filter(type=0)

            for webserver in webservers.all():
                server = webserver.server
                FabricApi(server.ip, server.deploy_user, server.deploy_pwd).update_symbolic_link(site.site_path, dest)

            oper.oper_status = 5 if all else 4
            site.online_version = oper.online_version
        except:
            oper.oper_status = 6
            site.status = 3
        finally:
            oper.deploy_status = 0
            oper.save()

            site.deploy_status = False
            site.pre_version = None
            site.save()
コード例 #11
0
ファイル: schema.py プロジェクト: 95ferreira/Manager_Pentests
 def mutate(root, info, input=None):
     ok = True
     site_instance = Site(name=input.name, urlBase=input.urlBase)
     site_instance.save()
     return CreateSite(ok=ok, site=site_instance)