Example #1
0
 def test_script(self, execute_manager):
     # The manage script is a replacement for the default manage.py
     # script. It has all the same bells and whistles since all it
     # does is call the normal Django stuff.
     manage.main('cheeseshop.development')
     self.assertEqual(execute_manager.call_args,
                      ((self.settings,), {}))
def run():
    # corre las migraciones de la base de datos
    manage.main(["manage.py", "syncdb"])

    print("Loading example data...")
    load_data.main()
    print("Example data loaded succesfully!")
Example #3
0
def main():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'project.test_utils.settings'
    sys.argv = [sys.argv[0], 'test'] + sys.argv[1:]
    # Go up two directories to project root:
    os.chdir(project_root)
    with PostgresContainerManager() as global_pcm:
        pcu.global_pcm = global_pcm
        manage.main()
Example #4
0
def test_args(mocker):
    dsn = "foobar"
    initdb = mocker.patch('manage.initdb')
    dropdb = mocker.patch('manage.dropdb')
    arguments = ['initdb', '--psql-dsn', dsn]
    manage.main(arguments)
    initdb.assert_called_with(dsn)

    arguments = ['dropdb', '--psql-dsn', dsn]
    manage.main(arguments)
    dropdb.assert_called_with(dsn)
Example #5
0
def run_tests(timeout, jobs):
    """
    Builds and runs all tests for all architectures for all systems
    """

    print('<testsuite>')
    for system in ['sel4', 'camkes']:
        manage.main(['env', system])
        manage.main(['solution'])
        for plat in PLATFORMS:
            run_plat_tests(plat, system, timeout, jobs)
    print('</testsuite>')
Example #6
0
    def test_manage_new_correct_usage(self):
        test_file = "testfilexyz.html"
        ls_before = glob.glob("content/*html")
        self.assertTrue(test_file not in ls_before)

        manage.main(["new", test_file])

        # move to teardown?
        if os.path.exists("content/" + test_file):
            os.remove("content/" + test_file)

        ls_after = glob.glob("content/*html")
        self.assertTrue("content/" + test_file not in ls_after)
Example #7
0
    def start(self,
              host="127.0.0.1",
              port="8000",
              production=False,
              reload=True):

        # check secret key.
        os.chdir(self.root)
        try:
            add_secret_key = Files.load(
                "__defaults__/env/json",
                format="json")["DJANGO_SECRET_KEY"] in [
                    "False", "True", "None", "", "null", None, False, True
                ]
        except:
            add_secret_key = True

        # import main.
        dev0s.env.export(export=["__defaults__/env/json"],
                         env={
                             "PRODUCTION": str(production),
                             "INTERACTIVE": False,
                         })
        if add_secret_key:
            dev0s.env.export(export=["__defaults__/env/json"],
                             env={
                                 "DJANGO_SECRET_KEY":
                                 String().generate(capitalize=True,
                                                   digits=True,
                                                   length=128),
                             })
        self.migrations()
        if dev0s.defaults.options.log_level >= 1:
            dev0s.response.log(f"Starting {self.name}.", save=True)
        sys.argv = [f"{self.root}/manage.py", "runserver", f"{host}:{port}"]
        if not reload: sys.argv += ["--noreload"]
        import manage
        manage.main()

        # handlers.
        return dev0s.response.success(
            f"Successfully stopped website [{self.root}].")
Example #8
0
def main():
  HERE = os.path.abspath(__file__)
  HERE = os.path.join(os.path.dirname(HERE), '..')
  HERE = os.path.normpath(HERE)

  WERKZEUG = [os.path.join(HERE, 'werkzeug')]
  DJANGO_EXTENSIONS = [os.path.join(HERE, 'django_extensions')]
  DJANGO = [os.path.join(HERE, 'django')]
  CASAM = [os.path.join(HERE, 'casam_django', 'casam')]
  PIL = [os.path.join(HERE, 'PIL')]
  if os.name == 'posix':
    VTK = []
  else:
    VTK = [os.path.join(HERE, 'VTK', 'lib', 'site-packages')]
  
  sys.path = VTK + PIL + WERKZEUG + DJANGO_EXTENSIONS + DJANGO + CASAM + sys.path

  print sys.path
  if len(sys.argv) == 1:
    sys.argv += ['runserver']

  import manage
  manage.main()

  from django.contrib.auth.models import Group
  try:
    gr1 = Group.objects.get(name='Beheerder')
  except Group.DoesNotExist:
    gr1 = Group(name='Beheerder')
    gr1.save()
    gr2 = Group(name='Chirurg')
    gr2.save()
    gr3 = Group(name='Onderzoeker')
    gr3.save()

  from django.conf import settings
  settings.DEBUG = True

  import django.core.signals

  # Log all exceptions detected by Django.
  django.core.signals.got_request_exception.connect(log_exception)
Example #9
0
    def test_manage_new_already_exists(self):
        test_file = "testfilexyz.html"
        ls_before = glob.glob("content/*html")
        self.assertTrue(test_file not in ls_before)

        with open("content/" + test_file, "w") as f:
            f.write("")

        ls_during = glob.glob("content/*html")
        self.assertTrue("content/" + test_file in ls_during)

        with self.assertRaises(SystemExit) as se:
            manage.main(["new", test_file])

        self.assertEqual(se.exception.code, manage.FILE_EXISTS)

        if os.path.exists("content/" + test_file):
            os.remove("content/" + test_file)

        ls_after = glob.glob("content/*html")
        self.assertTrue(test_file not in ls_after)
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# (c) 2014, Kevin Carter <*****@*****.**>
# (c) 2015, Major Hayden <*****@*****.**>
#
"""Returns data about containers and groups in tabular formats."""

# NOTE(nrb/palendae): The contents of this file were moved
# to manage.py in order to facilitate importing of the python code

# This file remains for backwards compatibility
import os
import sys

cwd = os.path.abspath(os.path.dirname(__file__))
import_path = os.path.join(cwd, '..', 'lib')
sys.path.append(import_path)

import manage

if __name__ == "__main__":
    manage.main()
import sys

from manage import main

if __name__ == '__main__':
    sys.argv[0] = "manage.py"
    sys.argv.append("import_models")
    """./manage.py import_models /home/yar/Downloads/Spool_models_import\ -\ Sheet1.csv"""
    sys.argv.append("/home/yar/Downloads/Spool_models_import.csv")
    print(sys.argv)
    main()
Example #12
0
def process(
    request_args: dict,
    jc: int,
    results: list,
    index: int,
    jxlmc: str,
    day: int,
):
    try:
        item: dict = results[index]
        jsmph, jasdm = item['jsmph'], item['JASDM']
        item_id, zylxdm = item['id'], item['zylxdm']
        jc_ks, jc_js = item['jc_ks'], item['jc_js']
        obj = {
            'jc': jc,
            'item': item,
            'index': index,
            'results': results,
        }

        if check_with_ehall(jasdm=jasdm, day=day, jc=str(jc), zylxdm=zylxdm):
            if zylxdm == '00':
                week_count, total_count = auto_correct(jxl=jxlmc,
                                                       jsmph=jsmph,
                                                       jasdm=jasdm,
                                                       day=day,
                                                       jc=str(jc))
                __Application.send_email(
                    subject="【南师教室】用户反馈:"
                    f"{jxlmc} "
                    f"{jsmph}教室 "
                    f"{jc_ks}-{jc_js}节有误 "
                    f"(当前为第{jc}节)",
                    message="验证一站式平台:数据一致\n"
                    f"上报计数:{total_count}\n"
                    f"本周计数:{week_count}\n"
                    f"操作方案:{'自动纠错' if total_count != week_count else None}\n"
                    f"反馈数据详情:{json.dumps(obj, ensure_ascii=False, indent=2)}\n"
                )

            else:
                __Application.send_email(
                    subject="【南师教室】用户反馈:"
                    f"{jxlmc} "
                    f"{jsmph}教室 "
                    f"{jc_ks}-{jc_js}节有误 "
                    f"(当前为第{jc}节)",
                    message=f"验证一站式平台:数据一致(非空教室)\n"
                    f"操作方案:None"
                    f"反馈数据详情:{json.dumps(obj, ensure_ascii=False, indent=2)}\n"
                )

        else:
            import manage
            from . import reset
            manage.main(manage.Namespace(run="Spider"))
            reset()

            __Application.send_email(
                subject="【南师教室】用户反馈:"
                f"{jxlmc} "
                f"{jsmph}教室 "
                f"{jc_ks}-{jc_js}节有误 "
                f"(当前为第{jc}节)",
                message=f"验证一站式平台:数据不一致\n"
                f"操作方案:更新数据库\n"
                f"反馈数据详情:{json.dumps(obj, ensure_ascii=False, indent=2)}\n")

    except Exception as e:
        logging.warning(f"{type(e), e}")
        __Application.send_email(
            subject="【南师教室】错误报告",
            message=f"{type(e), e}\n"
            f"{request.url}\n"
            f"{request_args}\n"
            f"{e.__traceback__.tb_frame.f_globals['__file__']}:{e.__traceback__.tb_lineno}\n"
        )
Example #13
0
    def test_manage_bad_args(self):
        try:
            manage.main([])
        except SystemExit as se:
            self.assertEqual(se.code, manage.INCORRECT_ARGS)

        try:
            manage.main(["new"])
        except SystemExit as se:
            self.assertEqual(se.code, manage.INCORRECT_ARGS)

        try:
            manage.main(["foo"])
        except SystemExit as se:
            self.assertEqual(se.code, manage.ARG_DOESNT_EXIST)

        try:
            manage.main(["build foo"])
        except SystemExit as se:
            self.assertEqual(se.code, manage.ARG_DOESNT_EXIST)

        try:
            manage.main(["foo", "bar"])
        except SystemExit as se:
            self.assertEqual(se.code, manage.ARG_DOESNT_EXIST)

        try:
            manage.main(["new", "foo", "bar"])
        except SystemExit as se:
            self.assertEqual(se.code, manage.INCORRECT_ARGS)
Example #14
0
logger = logging.getLogger(__name__)
try:
    dbinfo = DATABASES['default']
    dbname = dbinfo['NAME']
    while True:
        try:
            conn = connect(
                host=dbinfo['HOST'],
                user=dbinfo['USER'],
                password=dbinfo['PASSWORD']
            )
            break
        except Exception as e:
            logger.error(e)
            time.sleep(2)
    try:
        cs = conn.cursor()
        cs.execute(r"CREATE DATABASE `%s` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci" % dbname)
    except Exception as e:
        logger.error(e)
    if subprocess.run(["python", "manage.py", "sqldiff", "-a"]).returncode != 0:
        manage.main(["manage.py", "makemigrations", "--check"])
        manage.main(["manage.py", "migrate"])
except Exception as e:
    logger.error(e)
finally:
    listen_addr = os.getenv('LISTEN_ADDR', '0.0.0.0')
    listen_port = os.getenv('LISTEN_PORT', '8000')

    manage.main(["manage.py", "runserver", "%s:%s" % (listen_addr, listen_port)])
Example #15
0
    def Field_Route_info(self, rec_width, rec_height, path_width, turn_r, curve, straight, \
                         not_reverse, EX, GREE, offset_para):
        # 原始地块
        rectangle = cal.Rectangle(*init_point, rec_width, rec_height, 0)
        # 地头预留的偏置宽度
        offset_width = cal.Offset_width(turn_r, path_width, not_reverse,
                                        offset_para)
        # 内部矩形块、幅宽线,环形作业组、矩形作业转弯点
        rec_offset = cal.Rec_Offset(*init_point, rec_width, rec_height,
                                    offset_width)
        offset_parallel = cal.Offset_Parallel(*init_point, rec_width, rec_height, \
                                              offset_width, path_width)
        rec_mutil_offsets = cal.Rec_Mutil_offsets(*init_point, rec_width, rec_height, offset_width, \
                                                  path_width)
        top_point, low_point = cal.Rec_turn_point(*init_point, rec_width, rec_height, \
                                                  offset_width, path_width)

        # 调用调度算法
        if GREE:  # goole or-tools
            all_turn_length, row_list, all_turn_name = manage.main(*init_point, rec_width, \
                                                                   rec_height, offset_width, path_width, turn_r, curve,
                                                                   straight, not_reverse)
        if EX:  # 经验算法
            all_turn_length, row_list, all_turn_name = manage.Experience(*init_point, rec_width, \
                                                                         rec_height, offset_width, path_width, turn_r,
                                                                         curve, straight, not_reverse)

        # 矩形转弯线、路径线,环形路径线、转弯线,环形跨度线(作业路径)
        # 矩形路径(*row_list为了对最后一个作业行进行补长、截短)
        rectangle_routes = cal.Rectangle_routes(*init_point, rec_width, rec_height, offset_width, \
                                                turn_r, path_width, row_list, offset_para)
        circle_routes = cal.Circle_routes(*init_point, rec_width, rec_height, top_point, low_point, \
                                          row_list, offset_width, path_width, turn_r)
        circle_turn = cal.Circle_turn(*init_point, rec_width, rec_height, offset_width, path_width, \
                                      turn_r)
        # 环形行间跨行(*其中有部分是不作业的)
        c2c_turn = cal.C2C_turn(top_point, low_point, row_list, turn_r,
                                offset_width, path_width)
        x_, y_ = cal.Row_mark(row_list, top_point, low_point, path_width)

        # 进入线、矩形转弯线(非作业路径)
        route_in = cal.Rec_Route_In(*init_point, rec_width, rec_height,
                                    offset_width, path_width)
        all_turn = cal.All_Turn(*init_point, rec_width, rec_height, row_list, offset_width, \
                                path_width, turn_r, all_turn_name)

        # 矩形路径方向标识、环形路径方向标识(辅助功能)
        up_direction, down_direction = cal.Line_direction(row_list, top_point, low_point, \
                                                          path_width)
        circle_direction = cal.Circle_direction(*init_point, rec_width, rec_height, offset_width, \
                                                path_width, top_point, low_point, row_list)
        # 长度计算
        circle_turn_length = cal.Circle_turn_length(offset_width, path_width,
                                                    turn_r)
        circle_route_length = cal.Circle_route_length(*init_point, rec_width, rec_height, top_point, \
                                                      low_point, row_list, offset_width, path_width, turn_r)
        c2c_turn_length = cal.C2C_turn_length(offset_width, turn_r, path_width)
        rec_route_length = cal.Rec_Route_length(*init_point, rec_width, rec_height, turn_r, path_width, \
                                                row_list, offset_para)
        rec_route_in_length = cal.Rec_Route_In_length(offset_width)

        work_length = circle_turn_length + circle_route_length + c2c_turn_length + rec_route_length
        none_work_length = rec_route_in_length + all_turn_length
        work_length = round(work_length, 2)
        none_work_length = round(none_work_length, 2)
        return rectangle, rec_offset, route_in, rec_mutil_offsets, circle_routes, circle_turn, \
               offset_parallel, rectangle_routes, all_turn, c2c_turn, up_direction, down_direction, \
               circle_direction, x_, y_, row_list, work_length, none_work_length
Example #16
0
"""
Entrypoint module. This will hijack the script entrypoint to prevent circular
import errors if the top-level module is ran from the command line
(i.e. python -m prodstats)
"""
import sys

import loggers
from manage import main

loggers.config()

if __name__ == "__main__":
    sys.exit(main())
Example #17
0
import os
from channels.asgi import get_channel_layer
from ufs_tools.libtool import include_all

from manage import main


include_all(os.path.dirname(__file__), "server_base_packages")
main()
channel_layer = get_channel_layer()
Example #18
0
 def test_settings_error(self, sys_exit):
     # When the settings file cannot be imported the management
     # script it wil exit with a message and a specific exit code.
     manage.main('cheeseshop.tilsit')
     self.assertEqual(sys_exit.call_args, ((1,), {}))
Example #19
0
#!/home/matt/dailyprogrammer_blog/venv/bin/python3
import manage

manage.main("runserver", "0.0.0.0:64646")
Example #20
0
 def test_manage_build(self):
     exit_code = manage.main(["build"])
     self.assertEqual(exit_code, None)
Example #21
0
def main():
    """Defer to manage.py"""
    args = ['manage.py', 'eregs'] + sys.argv[1:]
    manage.main(args)
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# (c) 2014, Kevin Carter <*****@*****.**>
# (c) 2015, Major Hayden <*****@*****.**>
#
"""Returns data about containers and groups in tabular formats."""

# NOTE(nrb/palendae): The contents of this file were moved
# to manage.py in order to facilitate importing of the python code

# This file remains for backwards compatibility
import os
import sys

cwd = os.path.abspath(os.path.dirname(__file__))
import_path = os.path.join(cwd, '..', 'lib')
sys.path.append(import_path)

import manage

if __name__ == "__main__":
        manage.main()