python: Sort imports with isort.

Fixes #2665.

Regenerated by tabbott with `lint --fix` after a rebase and change in
parameters.

Note from tabbott: In a few cases, this converts technical debt in the
form of unsorted imports into different technical debt in the form of
our largest files having very long, ugly import sequences at the
start.  I expect this change will increase pressure for us to split
those files, which isn't a bad thing.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-06-10 15:54:34 -07:00 committed by Tim Abbott
parent b666aef2d3
commit 365fe0b3d5
528 changed files with 4801 additions and 3806 deletions

View File

@ -1,23 +1,35 @@
import logging
import time
from collections import OrderedDict, defaultdict
from datetime import datetime, timedelta
import logging
from typing import Callable, Dict, List, \
Optional, Tuple, Type, Union
from typing import Callable, Dict, List, Optional, Tuple, Type, Union
from django.conf import settings
from django.db import connection
from django.db.models import F
from psycopg2.sql import Composable, Identifier, Literal, SQL
from psycopg2.sql import SQL, Composable, Identifier, Literal
from analytics.models import BaseCount, \
FillState, InstallationCount, RealmCount, StreamCount, \
UserCount, installation_epoch, last_successful_fill
from analytics.models import (
BaseCount,
FillState,
InstallationCount,
RealmCount,
StreamCount,
UserCount,
installation_epoch,
last_successful_fill,
)
from zerver.lib.logging_util import log_to_file
from zerver.lib.timestamp import ceiling_to_day, \
ceiling_to_hour, floor_to_hour, verify_UTC
from zerver.models import Message, Realm, RealmAuditLog, \
Stream, UserActivityInterval, UserProfile, models
from zerver.lib.timestamp import ceiling_to_day, ceiling_to_hour, floor_to_hour, verify_UTC
from zerver.models import (
Message,
Realm,
RealmAuditLog,
Stream,
UserActivityInterval,
UserProfile,
models,
)
## Logging setup ##

View File

@ -4,6 +4,7 @@ from typing import List
from analytics.lib.counts import CountStat
def generate_time_series_data(days: int=100, business_hours_base: float=10,
non_business_hours_base: float=10, growth: float=1,
autocorrelation: float=0, spikiness: float=1,

View File

@ -4,6 +4,7 @@ from typing import List, Optional
from analytics.lib.counts import CountStat
from zerver.lib.timestamp import floor_to_day, floor_to_hour, verify_UTC
# If min_length is None, returns end_times from ceiling(start) to floor(end), inclusive.
# If min_length is greater than 0, pads the list to the left.
# So informally, time_range(Sep 20, Sep 22, day, None) returns [Sep 20, Sep 21, Sep 22],

View File

@ -8,8 +8,7 @@ from django.utils.timezone import now as timezone_now
from analytics.lib.counts import COUNT_STATS, CountStat
from analytics.models import installation_epoch, last_successful_fill
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day, \
floor_to_hour, verify_UTC
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day, floor_to_hour, verify_UTC
from zerver.models import Realm
states = {

View File

@ -1,21 +1,25 @@
from datetime import timedelta
from typing import Any, Dict, List, Mapping, Optional, Type
from unittest import mock
from django.core.management.base import BaseCommand
from django.utils.timezone import now as timezone_now
from analytics.lib.counts import COUNT_STATS, CountStat, \
do_drop_all_analytics_tables
from analytics.lib.counts import COUNT_STATS, CountStat, do_drop_all_analytics_tables
from analytics.lib.fixtures import generate_time_series_data
from analytics.lib.time_utils import time_range
from analytics.models import BaseCount, FillState, InstallationCount, \
RealmCount, StreamCount, UserCount
from analytics.models import (
BaseCount,
FillState,
InstallationCount,
RealmCount,
StreamCount,
UserCount,
)
from zerver.lib.actions import STREAM_ASSIGNMENT_COLORS, do_change_user_role
from zerver.lib.create_user import create_user
from zerver.lib.timestamp import floor_to_day
from zerver.models import Client, Realm, Recipient, Stream, Subscription, \
UserProfile
from zerver.models import Client, Realm, Recipient, Stream, Subscription, UserProfile
class Command(BaseCommand):

View File

@ -6,8 +6,17 @@ from django.core.management.base import BaseCommand, CommandError
from django.db.models import Count
from django.utils.timezone import now as timezone_now
from zerver.models import Message, Realm, Recipient, Stream, Subscription, \
UserActivity, UserMessage, UserProfile, get_realm
from zerver.models import (
Message,
Realm,
Recipient,
Stream,
Subscription,
UserActivity,
UserMessage,
UserProfile,
get_realm,
)
MOBILE_CLIENT_LIST = ["Android", "ios"]
HUMAN_CLIENT_LIST = MOBILE_CLIENT_LIST + ["website"]

View File

@ -4,8 +4,7 @@ from typing import Any
from django.core.management.base import BaseCommand, CommandError
from django.db.models import Q
from zerver.models import Message, Realm, Recipient, Stream, Subscription, \
get_realm
from zerver.models import Message, Realm, Recipient, Stream, Subscription, get_realm
class Command(BaseCommand):

View File

@ -1,8 +1,8 @@
import os
import time
from argparse import ArgumentParser
from typing import Any, Dict
from datetime import timezone
from typing import Any, Dict
from django.conf import settings
from django.core.management.base import BaseCommand

View File

@ -3,6 +3,7 @@ from django.db.backends.postgresql.schema import DatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models import Count, Sum
def clear_duplicate_counts(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
"""This is a preparatory migration for our Analytics tables.

View File

@ -7,6 +7,7 @@ from django.db.models import Q, UniqueConstraint
from zerver.lib.timestamp import floor_to_day
from zerver.models import Realm, Stream, UserProfile
class FillState(models.Model):
property: str = models.CharField(max_length=40, unique=True)
end_time: datetime.datetime = models.DateTimeField()

View File

@ -1,7 +1,7 @@
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional, Tuple, Type
from unittest import mock
import ujson
from django.apps import apps
from django.db import models
@ -10,24 +10,58 @@ from django.test import TestCase
from django.utils.timezone import now as timezone_now
from psycopg2.sql import SQL, Literal
from analytics.lib.counts import COUNT_STATS, CountStat, get_count_stats, \
DependentCountStat, LoggingCountStat, do_aggregate_to_summary_table, \
do_drop_all_analytics_tables, do_drop_single_stat, \
do_fill_count_stat_at_hour, do_increment_logging_stat, \
process_count_stat, sql_data_collector
from analytics.models import BaseCount, \
FillState, InstallationCount, RealmCount, StreamCount, \
UserCount, installation_epoch
from zerver.lib.actions import do_activate_user, do_create_user, \
do_deactivate_user, do_reactivate_user, update_user_activity_interval, \
do_invite_users, do_revoke_user_invite, do_resend_user_invite_email, \
InvitationError
from analytics.lib.counts import (
COUNT_STATS,
CountStat,
DependentCountStat,
LoggingCountStat,
do_aggregate_to_summary_table,
do_drop_all_analytics_tables,
do_drop_single_stat,
do_fill_count_stat_at_hour,
do_increment_logging_stat,
get_count_stats,
process_count_stat,
sql_data_collector,
)
from analytics.models import (
BaseCount,
FillState,
InstallationCount,
RealmCount,
StreamCount,
UserCount,
installation_epoch,
)
from zerver.lib.actions import (
InvitationError,
do_activate_user,
do_create_user,
do_deactivate_user,
do_invite_users,
do_reactivate_user,
do_resend_user_invite_email,
do_revoke_user_invite,
update_user_activity_interval,
)
from zerver.lib.create_user import create_user
from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day
from zerver.lib.topic import DB_TOPIC_NAME
from zerver.models import Client, Huddle, Message, Realm, \
RealmAuditLog, Recipient, Stream, UserActivityInterval, \
UserProfile, get_client, get_user, PreregistrationUser
from zerver.models import (
Client,
Huddle,
Message,
PreregistrationUser,
Realm,
RealmAuditLog,
Recipient,
Stream,
UserActivityInterval,
UserProfile,
get_client,
get_user,
)
class AnalyticsTestCase(TestCase):
MINUTE = timedelta(seconds = 60)

View File

@ -2,6 +2,7 @@ from analytics.lib.counts import CountStat
from analytics.lib.fixtures import generate_time_series_data
from zerver.lib.test_classes import ZulipTestCase
# A very light test suite; the code being tested is not run in production.
class TestFixtures(ZulipTestCase):
def test_deterministic_settings(self) -> None:

View File

@ -1,24 +1,21 @@
from datetime import datetime, timedelta, timezone
from typing import List, Optional
from unittest import mock
from django.http import HttpResponse
import ujson
from django.http import HttpResponse
from django.utils.timezone import now as timezone_now
from analytics.lib.counts import COUNT_STATS, CountStat
from analytics.lib.time_utils import time_range
from analytics.models import FillState, \
RealmCount, UserCount, last_successful_fill
from analytics.views import rewrite_client_arrays, \
sort_by_totals, sort_client_labels
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
from analytics.models import FillState, RealmCount, UserCount, last_successful_fill
from analytics.views import rewrite_client_arrays, sort_by_totals, sort_client_labels
from zerver.lib.actions import do_create_multiuse_invite_link, do_send_realm_reactivation_email
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timestamp import ceiling_to_day, \
ceiling_to_hour, datetime_to_timestamp
from zerver.lib.actions import do_create_multiuse_invite_link, \
do_send_realm_reactivation_email
from zerver.models import Client, get_realm, MultiuseInvite
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
from zerver.lib.timestamp import ceiling_to_day, ceiling_to_hour, datetime_to_timestamp
from zerver.models import Client, MultiuseInvite, get_realm
class TestStatsEndpoint(ZulipTestCase):
def test_stats(self) -> None:

View File

@ -6,54 +6,75 @@ import urllib
from collections import defaultdict
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from typing import Any, Callable, Dict, List, \
Optional, Set, Tuple, Type, Union
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Type, Union
import pytz
from django.conf import settings
from django.urls import reverse
from django.core.exceptions import ValidationError
from django.core.validators import URLValidator
from django.db import connection
from django.db.models.query import QuerySet
from django.http import HttpRequest, HttpResponse, HttpResponseNotFound
from django.shortcuts import render
from django.template import loader
from django.urls import reverse
from django.utils.timesince import timesince
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from django.utils.timesince import timesince
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError
from jinja2 import Markup as mark_safe
from psycopg2.sql import Composable, Literal, SQL
from psycopg2.sql import SQL, Composable, Literal
from analytics.lib.counts import COUNT_STATS, CountStat
from analytics.lib.time_utils import time_range
from analytics.models import BaseCount, InstallationCount, \
RealmCount, StreamCount, UserCount, last_successful_fill, installation_epoch
from confirmation.models import Confirmation, confirmation_url, _properties
from zerver.decorator import require_server_admin, require_server_admin_api, \
to_utc_datetime, zulip_login_required, require_non_guest_user
from analytics.models import (
BaseCount,
InstallationCount,
RealmCount,
StreamCount,
UserCount,
installation_epoch,
last_successful_fill,
)
from confirmation.models import Confirmation, _properties, confirmation_url
from confirmation.settings import STATUS_ACTIVE
from zerver.decorator import (
require_non_guest_user,
require_server_admin,
require_server_admin_api,
to_utc_datetime,
zulip_login_required,
)
from zerver.lib.actions import (
do_change_plan_type,
do_deactivate_realm,
do_scrub_realm,
do_send_realm_reactivation_email,
)
from zerver.lib.exceptions import JsonableError
from zerver.lib.realm_icon import realm_icon_url
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
from zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetime
from zerver.lib.realm_icon import realm_icon_url
from zerver.views.invite import get_invitee_emails_set
from zerver.lib.subdomains import get_subdomain_from_hostname
from zerver.lib.actions import do_change_plan_type, do_deactivate_realm, \
do_send_realm_reactivation_email, do_scrub_realm
from zerver.lib.timestamp import convert_to_UTC, timestamp_to_datetime
from zerver.lib.validator import to_non_negative_int
from confirmation.settings import STATUS_ACTIVE
from zerver.views.invite import get_invitee_emails_set
if settings.BILLING_ENABLED:
from corporate.lib.stripe import attach_discount_to_realm, get_discount_for_realm
from zerver.models import Client, get_realm, Realm, UserActivity, UserActivityInterval, \
UserProfile, PreregistrationUser, MultiuseInvite
from zerver.models import (
Client,
MultiuseInvite,
PreregistrationUser,
Realm,
UserActivity,
UserActivityInterval,
UserProfile,
get_realm,
)
if settings.ZILENCER_ENABLED:
from zilencer.models import RemoteInstallationCount, RemoteRealmCount, \
RemoteZulipServer
from zilencer.models import RemoteInstallationCount, RemoteRealmCount, RemoteZulipServer
else:
from unittest.mock import Mock
RemoteInstallationCount = Mock() # type: ignore[misc] # https://github.com/JukkaL/mypy/issues/1188

View File

@ -1,5 +1,5 @@
from django.db import models, migrations
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,5 +1,5 @@
from django.db import models, migrations
import django.utils.timezone
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,7 +1,6 @@
# Generated by Django 1.11.6 on 2017-11-30 00:13
from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):

View File

@ -1,24 +1,23 @@
# Copyright: (c) 2008, Jarek Zgoda <jarek.zgoda@gmail.com>
__revision__ = '$Id: models.py 28 2009-10-22 15:03:02Z jarek.zgoda $'
import datetime
import string
from random import SystemRandom
from typing import Dict, Optional, Union
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import CASCADE
from django.urls import reverse
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.urls import reverse
from django.utils.timezone import now as timezone_now
from zerver.models import PreregistrationUser, EmailChangeStatus, MultiuseInvite, \
UserProfile, Realm
from random import SystemRandom
import string
from typing import Dict, Optional, Union
from zerver.models import EmailChangeStatus, MultiuseInvite, PreregistrationUser, Realm, UserProfile
class ConfirmationKeyException(Exception):
WRONG_LENGTH = 1

View File

@ -1,26 +1,31 @@
from datetime import datetime, timedelta
from decimal import Decimal
from functools import wraps
import logging
import math
import os
from typing import Any, Callable, Dict, Optional, TypeVar, Tuple, cast
import ujson
from datetime import datetime, timedelta
from decimal import Decimal
from functools import wraps
from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, cast
from django.conf import settings
from django.db import transaction
from django.utils.translation import ugettext as _
from django.utils.timezone import now as timezone_now
from django.core.signing import Signer
import stripe
import ujson
from django.conf import settings
from django.core.signing import Signer
from django.db import transaction
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from corporate.models import (
Customer,
CustomerPlan,
LicenseLedger,
get_current_plan_by_customer,
get_current_plan_by_realm,
get_customer_by_realm,
)
from zerver.lib.logging_util import log_to_file
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
from zerver.lib.utils import generate_random_token
from zerver.models import Realm, UserProfile, RealmAuditLog
from corporate.models import Customer, CustomerPlan, LicenseLedger, \
get_current_plan_by_customer, get_customer_by_realm, \
get_current_plan_by_realm
from zerver.models import Realm, RealmAuditLog, UserProfile
from zproject.config import get_secret
STRIPE_PUBLISHABLE_KEY = get_secret('stripe_publishable_key')

View File

@ -7,6 +7,7 @@ from django.db.models import CASCADE
from zerver.models import Realm
class Customer(models.Model):
realm: Realm = models.OneToOneField(Realm, on_delete=CASCADE)
stripe_customer_id: str = models.CharField(max_length=255, null=True, unique=True)

View File

@ -1,43 +1,66 @@
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from functools import wraps
from unittest.mock import Mock, patch
import json
import operator
import os
import re
import sys
from typing import Any, Callable, Dict, List, Optional, TypeVar, Tuple, cast
import ujson
import json
import responses
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from functools import wraps
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, cast
from unittest.mock import Mock, patch
from django.core import signing
from django.urls.resolvers import get_resolver
from django.http import HttpResponse
import responses
import stripe
import ujson
from django.conf import settings
from django.core import signing
from django.http import HttpResponse
from django.urls.resolvers import get_resolver
from django.utils.timezone import now as timezone_now
import stripe
from zerver.lib.actions import do_deactivate_user, do_create_user, \
do_activate_user, do_reactivate_user, do_deactivate_realm, \
do_reactivate_realm
from corporate.lib.stripe import (
MAX_INVOICED_LICENSES,
MIN_INVOICED_LICENSES,
BillingError,
StripeCardError,
add_months,
attach_discount_to_realm,
catch_stripe_errors,
compute_plan_parameters,
get_discount_for_realm,
get_latest_seat_count,
invoice_plan,
invoice_plans_as_needed,
make_end_of_cycle_updates_if_needed,
next_month,
process_initial_upgrade,
sign_string,
stripe_get_customer,
unsign_string,
update_license_ledger_for_automanaged_plan,
update_license_ledger_if_needed,
update_or_create_stripe_customer,
)
from corporate.models import (
Customer,
CustomerPlan,
LicenseLedger,
get_current_plan_by_customer,
get_current_plan_by_realm,
get_customer_by_realm,
)
from zerver.lib.actions import (
do_activate_user,
do_create_user,
do_deactivate_realm,
do_deactivate_user,
do_reactivate_realm,
do_reactivate_user,
)
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
from zerver.models import Realm, UserProfile, get_realm, RealmAuditLog
from corporate.lib.stripe import catch_stripe_errors, attach_discount_to_realm, \
get_latest_seat_count, sign_string, unsign_string, \
BillingError, StripeCardError, stripe_get_customer, \
MIN_INVOICED_LICENSES, MAX_INVOICED_LICENSES, \
add_months, next_month, \
compute_plan_parameters, update_or_create_stripe_customer, \
process_initial_upgrade, make_end_of_cycle_updates_if_needed, \
update_license_ledger_if_needed, update_license_ledger_for_automanaged_plan, \
invoice_plan, invoice_plans_as_needed, get_discount_for_realm
from corporate.models import Customer, CustomerPlan, LicenseLedger, \
get_customer_by_realm, get_current_plan_by_customer, \
get_current_plan_by_realm
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
from zerver.models import Realm, RealmAuditLog, UserProfile, get_realm
CallableT = TypeVar('CallableT', bound=Callable[..., Any])

View File

@ -1,8 +1,8 @@
from typing import Any
from django.views.generic import TemplateView
from django.conf.urls import include
from django.urls import path
from django.views.generic import TemplateView
import corporate.views
from zerver.lib.rest import rest_dispatch

View File

@ -1,30 +1,45 @@
import logging
from decimal import Decimal
import stripe
from typing import Any, Dict, cast, Optional, Union
from typing import Any, Dict, Optional, Union, cast
import stripe
from django.conf import settings
from django.core import signing
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from django.shortcuts import render
from django.urls import reverse
from django.conf import settings
from django.utils.timezone import now as timezone_now
from django.utils.translation import ugettext as _
from zerver.decorator import zulip_login_required, require_billing_access
from corporate.lib.stripe import (
DEFAULT_INVOICE_DAYS_UNTIL_DUE,
MAX_INVOICED_LICENSES,
MIN_INVOICED_LICENSES,
STRIPE_PUBLISHABLE_KEY,
BillingError,
do_change_plan_status,
do_replace_payment_source,
downgrade_now,
get_latest_seat_count,
make_end_of_cycle_updates_if_needed,
process_initial_upgrade,
renewal_amount,
sign_string,
start_of_next_billing_cycle,
stripe_get_customer,
unsign_string,
)
from corporate.models import (
CustomerPlan,
get_current_plan_by_customer,
get_current_plan_by_realm,
get_customer_by_realm,
)
from zerver.decorator import require_billing_access, zulip_login_required
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, json_success
from zerver.lib.validator import check_string, check_int
from zerver.lib.validator import check_int, check_string
from zerver.models import UserProfile
from corporate.lib.stripe import STRIPE_PUBLISHABLE_KEY, \
stripe_get_customer, get_latest_seat_count, \
process_initial_upgrade, sign_string, \
unsign_string, BillingError, do_change_plan_status, do_replace_payment_source, \
MIN_INVOICED_LICENSES, MAX_INVOICED_LICENSES, DEFAULT_INVOICE_DAYS_UNTIL_DUE, \
start_of_next_billing_cycle, renewal_amount, \
make_end_of_cycle_updates_if_needed, downgrade_now
from corporate.models import CustomerPlan, get_current_plan_by_customer, \
get_customer_by_realm, get_current_plan_by_realm
billing_logger = logging.getLogger('corporate.stripe')

View File

@ -10,10 +10,8 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sys
from typing import Any, Dict, List, Optional
# If extensions (or modules to document with autodoc) are in another directory,
@ -310,6 +308,7 @@ source_suffix = {
# See https://github.com/zulip/zulip/issues/13263 for details.
from recommonmark.parser import CommonMarkParser
class CustomCommonMarkParser(CommonMarkParser):
def visit_document(self, node):
pass

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
import argparse
import glob
import os
import shlex
import subprocess
import sys
import os
import glob
import shlex
#
# In order to use remote casperjs debugging, pass the --remote-debug flag
@ -64,13 +64,14 @@ sys.path.insert(0, ZULIP_PATH)
# check for the venv
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
from typing import Iterable, List
from tools.lib.test_script import assert_provisioning_status_ok, find_js_test_files
from tools.lib.test_server import test_server_running
from typing import Iterable, List
assert_provisioning_status_ok(options.force)
os.chdir(ZULIP_PATH)

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python3
import configparser
import os
import sys
import configparser
if sys.version_info <= (3, 0):
print("Error: Zulip is a Python 3 project, and cannot be run with Python 2.")
print("Use e.g. `/path/to/manage.py` not `python /path/to/manage.py`.")
@ -37,6 +38,7 @@ if __name__ == "__main__":
from django.conf import settings
from django.core.management import execute_from_command_line
from django.core.management.base import CommandError
from scripts.lib.zulip_tools import log_management_command
log_management_command(" ".join(sys.argv), settings.MANAGEMENT_LOG_PATH)

View File

@ -6,6 +6,7 @@ import sys
import time
from typing import Tuple
def nagios_from_file(results_file: str, max_time_diff: int=60 * 2) -> 'Tuple[int, str]':
"""Returns a nagios-appropriate string and return code obtained by
parsing the desired file on disk. The file on disk should be of format

View File

@ -8,12 +8,12 @@ It supports both munin and nagios outputs
It must be run on a machine that is using the live database for the
Django ORM.
"""
import sys
import argparse
import os
import random
import sys
import time
import traceback
import os
sys.path.append('.')
sys.path.append('/home/zulip/deployments/current')
@ -21,10 +21,10 @@ from scripts.lib.setup_path import setup_path
setup_path()
import django
from typing import Any, Dict, List, Optional
import django
usage = """Usage: send-receive.py [options] [config]
'config' is optional, if present will return config info.
@ -75,9 +75,10 @@ os.environ['DJANGO_SETTINGS_MODULE'] = "zproject.settings"
django.setup()
from zerver.models import get_system_bot
from django.conf import settings
from zerver.models import get_system_bot
states = {
"OK": 0,
"WARNING": 1,

View File

@ -4,10 +4,9 @@
Nagios plugin to check the difference between the primary and
secondary Postgres servers' xlog location.
"""
import configparser
import subprocess
import re
import subprocess
from typing import NoReturn
states = {

View File

@ -4,6 +4,7 @@
Nagios plugin to check the length of the FTS update log.
"""
import sys
sys.path.append('/home/zulip/deployments/current')
try:
from scripts.lib.setup_path import setup_path

View File

@ -1,16 +1,16 @@
#!/usr/bin/env python3
import os
import sys
import glob
import logging
import os
import shlex
import subprocess
import logging
import dateutil.parser
import sys
import time
from datetime import datetime, timedelta, timezone
from typing import Dict, List
import dateutil.parser
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger(__name__)

View File

@ -23,14 +23,15 @@ except ImportError:
pass
import argparse
import configparser
import logging
import os
import select
import sys
import time
import psycopg2
import psycopg2.extensions
import select
import time
import logging
import configparser
import sys
import os
BATCH_SIZE = 1000

View File

@ -8,9 +8,9 @@ This script works by just monitoring the files under
mirrors when they receive the messages sent every minute by
/etc/cron.d/test_zephyr_personal_mirrors
"""
from typing import Dict
import os
import time
from typing import Dict
RESULTS_DIR: str = "/home/zulip/mirror_status"

View File

@ -24,9 +24,9 @@ sys.path.append('/home/zulip/deployments/current/zerver')
django.setup()
from zerver.models import UserActivity
from typing import Any, Dict, Optional, Set
from typing import Any, Dict, Set, Optional
from zerver.models import UserActivity
states: Dict[str, int] = {
"OK": 0,

View File

@ -9,9 +9,9 @@ run out of cron.
See puppet/zulip_ops/files/cron.d/zephyr-mirror for the crontab details.
"""
from typing import Dict
import os
import time
from typing import Dict
RESULTS_FILE = "/var/lib/nagios_state/check-mirroring-results"

View File

@ -40,16 +40,15 @@ Note that it currently does not handle the deconfiguration of
interfaces.
'''
import sys
import logging
import logging.handlers
import subprocess
import sys
from typing import Optional
import boto.utils
import netifaces
from typing import Optional
def address_of(device_id: int) -> Optional[str]:
try:

View File

@ -1,9 +1,8 @@
import json
import os
import re
import time
import subprocess
import json
import time
from collections import defaultdict
from typing import Any, DefaultDict, Dict, List

View File

@ -4,8 +4,9 @@ import sys
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib import clean_emoji_cache, clean_node_cache, clean_venv_cache
from scripts.lib.zulip_tools import parse_cache_script_args
from scripts.lib import clean_venv_cache, clean_node_cache, clean_emoji_cache
def main() -> None:
args = parse_cache_script_args("This script cleans unused zulip caches.")

View File

@ -2,14 +2,16 @@
import argparse
import os
import sys
from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import \
get_environment, get_recent_deployments, \
parse_cache_script_args, purge_unused_caches
from scripts.lib.zulip_tools import (
get_environment,
get_recent_deployments,
parse_cache_script_args,
purge_unused_caches,
)
ENV = get_environment()
EMOJI_CACHE_PATH = "/srv/zulip-emoji-cache"

View File

@ -2,14 +2,16 @@
import argparse
import os
import sys
from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import \
get_environment, get_recent_deployments, parse_cache_script_args, \
purge_unused_caches
from scripts.lib.zulip_tools import (
get_environment,
get_recent_deployments,
parse_cache_script_args,
purge_unused_caches,
)
ENV = get_environment()
NODE_MODULES_CACHE_PATH = "/srv/zulip-npm-cache"

View File

@ -3,15 +3,17 @@ import argparse
import glob
import os
import sys
from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib.hash_reqs import expand_reqs, hash_deps
from scripts.lib.zulip_tools import \
get_environment, get_recent_deployments, parse_cache_script_args, \
purge_unused_caches
from scripts.lib.zulip_tools import (
get_environment,
get_recent_deployments,
parse_cache_script_args,
purge_unused_caches,
)
ENV = get_environment()
VENV_CACHE_DIR = '/srv/zulip-venv-cache'

View File

@ -1,17 +1,14 @@
#!/usr/bin/env python3
import os
import argparse
import os
import sys
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if ZULIP_PATH not in sys.path:
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import os_families, overwrite_symlink, run, parse_os_release
from scripts.lib.setup_venv import (
setup_virtualenv, get_venv_dependencies,
)
from scripts.lib.setup_venv import get_venv_dependencies, setup_virtualenv
from scripts.lib.zulip_tools import os_families, overwrite_symlink, parse_os_release, run
parser = argparse.ArgumentParser(description="Create a production virtualenv with caching")
parser.add_argument("deploy_path")

View File

@ -1,17 +1,18 @@
#!/usr/bin/env python3
import os
import argparse
import os
import sys
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
if ZULIP_PATH not in sys.path:
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import os_families, run, parse_os_release
from scripts.lib.setup_venv import (
setup_virtualenv, THUMBOR_VENV_DEPENDENCIES, YUM_THUMBOR_VENV_DEPENDENCIES,
THUMBOR_VENV_DEPENDENCIES,
YUM_THUMBOR_VENV_DEPENDENCIES,
setup_virtualenv,
)
from scripts.lib.zulip_tools import os_families, parse_os_release, run
parser = argparse.ArgumentParser(description="Create a thumbor virtualenv with caching")
parser.add_argument("deploy_path")

View File

@ -40,21 +40,16 @@ Also you can use optional keys to configure the script and change default values
-t Disable sending request to the Zulip server. Default value: False.
"""
import argparse
import json
import os
import posix
import ssl
import sys
import argparse
import posix
import json
from urllib.parse import urljoin, urlencode
from urllib.request import Request, urlopen
from urllib.error import HTTPError
from configparser import RawConfigParser
from urllib.error import HTTPError
from urllib.parse import urlencode, urljoin
from urllib.request import Request, urlopen
parser = argparse.ArgumentParser()

View File

@ -1,10 +1,11 @@
#!/usr/bin/env python3
import os
import sys
import argparse
import hashlib
import os
import sys
from typing import Iterable, List, MutableSet
def expand_reqs_helper(fpath: str, visited: MutableSet[str]) -> List[str]:
if fpath in visited:
return []

View File

@ -1,10 +1,10 @@
import os
import hashlib
import json
import os
import shutil
from typing import List, Optional
from typing import Optional, List
from scripts.lib.zulip_tools import subprocess_text_output, run
from scripts.lib.zulip_tools import run, subprocess_text_output
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
ZULIP_SRV_PATH = "/srv"

View File

@ -1,8 +1,9 @@
try:
from django.conf import settings # noqa: F401
from zerver.models import * # noqa: F401, F403
from zerver.lib.actions import * # noqa: F401, F403
from analytics.models import * # noqa: F401, F403
from zerver.lib.actions import * # noqa: F401, F403
from zerver.models import * # noqa: F401, F403
except Exception:
import traceback
print("\nException importing Zulip core modules on startup!")

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
import argparse
import os
import sys
@ -13,6 +12,7 @@ setup_path()
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
import django
django.setup()
from zerver.worker.queue_processors import get_active_worker_queues

View File

@ -1,10 +1,10 @@
"""
Use libraries from a virtualenv (by modifying sys.path) in production.
"""
import os
import sys
def setup_path() -> None:
if os.path.basename(sys.prefix) != "zulip-py3-venv":
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

View File

@ -2,10 +2,10 @@ import logging
import os
import shutil
import subprocess
from scripts.lib.zulip_tools import run, run_as_root, ENDC, WARNING, os_families
from scripts.lib.hash_reqs import expand_reqs
from typing import List, Optional, Set, Tuple
from typing import List, Optional, Tuple, Set
from scripts.lib.hash_reqs import expand_reqs
from scripts.lib.zulip_tools import ENDC, WARNING, os_families, run, run_as_root
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
VENV_CACHE_PATH = "/srv/zulip-venv-cache"

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
import json
import os
import subprocess
@ -14,6 +13,7 @@ setup_path()
from scripts.lib.zulip_tools import get_config_file
def write_realm_nginx_config_line(f: Any, host: str, port: str) -> None:
f.write("""if ($host = '{}') {{
set $tornado_server http://tornado{};

View File

@ -1,17 +1,24 @@
#!/usr/bin/env python3
import glob
import os
import shutil
import sys
import subprocess
import sys
import tempfile
import glob
os.environ["PYTHONUNBUFFERED"] = "y"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', ".."))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, make_deploy_path, \
get_deployment_version, is_invalid_upgrade, overwrite_symlink
import version
from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
ENDC,
FAIL,
get_deployment_version,
is_invalid_upgrade,
make_deploy_path,
overwrite_symlink,
)
if len(sys.argv) != 2:
print(FAIL + f"Usage: {sys.argv[0]} <tarball>" + ENDC)

View File

@ -1,19 +1,27 @@
#!/usr/bin/env python3
import configparser
import logging
import os
import shutil
import sys
import subprocess
import logging
import sys
import time
import configparser
TARBALL_ARCHIVE_PATH = "/home/zulip/archives"
os.environ["PYTHONUNBUFFERED"] = "y"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, FAIL, ENDC, \
su_to_zulip, get_deployment_lock, release_deployment_lock, assert_running_as_root, \
get_config_file, get_deploy_options
from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
ENDC,
FAIL,
assert_running_as_root,
get_config_file,
get_deploy_options,
get_deployment_lock,
release_deployment_lock,
su_to_zulip,
)
config_file: configparser.RawConfigParser = get_config_file()
deploy_options = get_deploy_options(config_file)

View File

@ -1,18 +1,27 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
import logging
import time
import argparse
import logging
import os
import subprocess
import sys
import time
LOCAL_GIT_CACHE_DIR = '/srv/zulip.git'
os.environ["PYTHONUNBUFFERED"] = "y"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, make_deploy_path, \
get_deployment_lock, overwrite_symlink, release_deployment_lock, su_to_zulip, assert_running_as_root, \
get_config_file, get_deploy_options, get_config
from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
assert_running_as_root,
get_config,
get_config_file,
get_deploy_options,
get_deployment_lock,
make_deploy_path,
overwrite_symlink,
release_deployment_lock,
su_to_zulip,
)
config_file = get_config_file()
deploy_options = get_deploy_options(config_file)

View File

@ -8,10 +8,10 @@ import argparse
import configparser
import glob
import hashlib
import subprocess
import os
import sys
import logging
import os
import subprocess
import sys
import time
os.environ["PYTHONUNBUFFERED"] = "y"
@ -22,8 +22,12 @@ os.environ["LANG"] = "en_US.UTF-8"
os.environ["LANGUAGE"] = "en_US.UTF-8"
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, su_to_zulip, \
assert_running_as_root, parse_os_release
from scripts.lib.zulip_tools import (
DEPLOYMENTS_DIR,
assert_running_as_root,
parse_os_release,
su_to_zulip,
)
assert_running_as_root()

View File

@ -1,8 +1,10 @@
#!/usr/bin/env python3
import argparse
import configparser
import datetime
import functools
import hashlib
import json
import logging
import os
import pwd
@ -13,11 +15,8 @@ import subprocess
import sys
import tempfile
import time
import json
import uuid
import configparser
from typing import Sequence, Set, Any, Dict, List
from typing import Any, Dict, List, Sequence, Set
DEPLOYMENTS_DIR = "/home/zulip/deployments"
LOCK_DIR = os.path.join(DEPLOYMENTS_DIR, "lock")

View File

@ -1,12 +1,11 @@
#!/usr/bin/env python3
import sys
import time
import argparse
import configparser
from collections import defaultdict
import os
import subprocess
import sys
import time
from collections import defaultdict
from typing import Dict
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

View File

@ -1,7 +1,7 @@
import time
from typing import Tuple
def nagios_from_file(results_file: str) -> Tuple[int, str]:
"""Returns a nagios-appropriate string and return code obtained by
parsing the desired file on disk. The file on disk should be of format

View File

@ -3,13 +3,12 @@ import argparse
import os
import subprocess
import sys
from typing import Set
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, get_recent_deployments, \
may_be_perform_purging
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, get_recent_deployments, may_be_perform_purging
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(

View File

@ -1,16 +1,16 @@
#!/usr/bin/env python3
import argparse
import configparser
import os
import sys
import pwd
import subprocess
import logging
import time
import os
import pwd
import shlex
import subprocess
import sys
import time
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.zulip_tools import ENDC, OKGREEN, WARNING, DEPLOYMENTS_DIR, overwrite_symlink
from scripts.lib.zulip_tools import DEPLOYMENTS_DIR, ENDC, OKGREEN, WARNING, overwrite_symlink
logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s restart-server: %(message)s",

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
import os
import sys
@ -10,9 +9,10 @@ from scripts.lib.setup_path import setup_path
setup_path()
from zproject import settings
import pylibmc
from zproject import settings
pylibmc.Client(
[settings.MEMCACHED_LOCATION],
binary=True,

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python3
# This tools generates /etc/zulip/zulip-secrets.conf
import sys
import os
import sys
from typing import Dict, List
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
@ -15,8 +13,8 @@ setup_path()
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
import argparse
import uuid
import configparser
import uuid
os.chdir(os.path.join(os.path.dirname(__file__), '..', '..'))
@ -140,6 +138,7 @@ def generate_secrets(development: bool = False) -> None:
# file directly.
import redis
from zerver.lib.redis_utils import get_redis_client
redis_password = random_token()

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python3
import os
from premailer import Premailer
from cssutils import profile
from cssutils.profiles import Profiles, properties, macros
from typing import Set
from cssutils import profile
from cssutils.profiles import Profiles, macros, properties
from premailer import Premailer
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
EMAIL_TEMPLATES_PATH = os.path.join(ZULIP_PATH, 'templates', 'zerver', 'emails')
COMPILED_EMAIL_TEMPLATES_PATH = os.path.join(EMAIL_TEMPLATES_PATH, 'compiled')

View File

@ -1,17 +1,15 @@
#!/usr/bin/env python3
import argparse
import os
import re
import subprocess
import sys
import tempfile
from typing import IO
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(BASE_DIR)
from scripts.lib.zulip_tools import su_to_zulip, run
from scripts.lib.zulip_tools import run, su_to_zulip
POSTGRES_USER = "postgres"

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
import configparser
import os
import re
from lib.zulip_tools import parse_os_release, assert_running_as_root
import subprocess
import sys
from lib.zulip_tools import assert_running_as_root, parse_os_release
assert_running_as_root()
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
import subprocess
from xml.etree import ElementTree as ET
# Generates the favicon images containing unread message counts.

View File

@ -2,6 +2,7 @@
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import argparse
@ -12,8 +13,7 @@ import subprocess
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.zulip_tools import WARNING, FAIL, ENDC
from scripts.lib.zulip_tools import ENDC, FAIL, WARNING
from tools.lib.capitalization import check_capitalization
DJANGO_PO_REGEX = re.compile('msgid "(.*?)"')

View File

@ -1,18 +1,20 @@
#!/usr/bin/env python3
from typing import List
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
import argparse
import json
import os
import sys
import subprocess
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.zulip_tools import WARNING, FAIL, ENDC
from scripts.lib.zulip_tools import ENDC, FAIL, WARNING
def find_handlebars(translatable_strings: List[str]) -> List[str]:
errored = []

View File

@ -1,13 +1,13 @@
#!/usr/bin/env python3
import argparse
import os
import re
import sys
from typing import Any, Dict, Optional
import requests
import re
import argparse
import sys
import os
import ConfigParser
from typing import Any, Dict, Optional
# Scans zulip repositary for issues that don't have any `area` labels.
# GitHub API token is required as GitHub limits unauthenticated

View File

@ -1,16 +1,14 @@
#!/usr/bin/env python3
import os
import argparse
import os
import sys
tools_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir)
from tools.lib.test_script import (
assert_provisioning_status_ok,
)
from tools.lib.test_script import assert_provisioning_status_ok
def run() -> None:
parser = argparse.ArgumentParser()

View File

@ -1,18 +1,20 @@
#!/usr/bin/env python3
from lib.template_parser import validate
from lib.html_branches import build_id_dict
from lib.pretty_print import validate_indent_html
import argparse
import sys
import logging
import sys
# check for the venv
from lib import sanity_check
from lib.html_branches import build_id_dict
from lib.pretty_print import validate_indent_html
from lib.template_parser import validate
sanity_check.check_venv(__file__)
from zulint import lister
from typing import Dict, Iterable, List
from zulint import lister
EXCLUDED_FILES = [
## Test data Files for testing modules in tests
"tools/tests/test_template_data",

View File

@ -7,12 +7,12 @@ Disclaimer: This script is not a lawyer. It cannot validate that the
claimed licenses are correct. It can only check for basic syntactic
issues.
"""
import difflib
import io
import os
import subprocess
import sys
from debian import copyright
COPYRIGHT_FILENAME = "docs/THIRDPARTY"

View File

@ -2,14 +2,15 @@
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from collections import defaultdict
from typing import Any, Dict, List, Set
sanity_check.check_venv(__file__)
import html
import os
import pprint
from collections import defaultdict
from typing import Any, Dict, List, Set
import ujson
Call = Dict[str, Any]

View File

@ -1,17 +1,16 @@
#!/usr/bin/env python3
import os
import platform
import shlex
import sys
import subprocess
import sys
from typing import Callable, List
TOOLS_DIR = os.path.dirname(__file__)
ROOT_DIR = os.path.dirname(TOOLS_DIR)
sys.path.insert(0, ROOT_DIR)
from scripts.lib.zulip_tools import get_dev_uuid_var_path
UUID_VAR_PATH = get_dev_uuid_var_path()
def run(check_func: Callable[[], bool]) -> None:
@ -88,7 +87,7 @@ def test_models() -> bool:
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
import django
django.setup()
from zerver.models import UserProfile, Realm
from zerver.models import Realm, UserProfile
print('Num realms: ', Realm.objects.count())
print('Num users: ', UserProfile.objects.count())
return True

View File

@ -1,8 +1,9 @@
import optparse
from scrapy.crawler import Crawler
from scrapy.commands import crawl
from typing import List, Union
from scrapy.commands import crawl
from scrapy.crawler import Crawler
class Command(crawl.Command):
def run(self, args: List[str], opts: optparse.Values) -> None:

View File

@ -1,6 +1,5 @@
import os
import pathlib
from typing import List
from .common.spiders import BaseDocumentationSpider

View File

@ -1,12 +1,10 @@
import os
from posixpath import basename
from typing import Any, List, Set
from urllib.parse import urlparse
from .common.spiders import BaseDocumentationSpider
from typing import Any, List, Set
def get_images_dir(images_path: str) -> str:
# Get index html file as start url and convert it to file uri

View File

@ -1,7 +1,8 @@
import json
import re
import scrapy
from typing import Callable, Iterable, List, Optional, Union
import scrapy
from scrapy.http import Request, Response
from scrapy.linkextractors import IGNORED_EXTENSIONS
from scrapy.linkextractors.lxmlhtml import LxmlLinkExtractor
@ -9,8 +10,6 @@ from scrapy.spidermiddlewares.httperror import HttpError
from scrapy.utils.url import url_has_any_extension
from twisted.python.failure import Failure
from typing import Callable, Iterable, List, Optional, Union
EXCLUDED_URLS = [
# Google calendar returns 404s on HEAD requests unconditionally
'https://calendar.google.com/calendar/embed?src=ktiduof4eoh47lmgcl2qunnc0o@group.calendar.google.com',

View File

@ -9,13 +9,12 @@
# machine:
#
# $ python3 add_mentor.py --remove <mentor's username>
import os
import re
import socket
import sys
from argparse import ArgumentParser
from typing import List
import socket
import re
import requests

View File

@ -14,19 +14,18 @@
# Copy conf.ini-template to conf.ini and populate with your api token.
#
# usage: python3 create.py <username>
import sys
import argparse
import configparser
import json
import os
import sys
import time
import urllib.error
import urllib.request
import json
import digitalocean
import time
import argparse
import os
from typing import Any, Dict, List
import digitalocean
# initiation argument parser
parser = argparse.ArgumentParser(description='Create a Zulip devopment VM Digital Ocean droplet.')
parser.add_argument("username", help="Github username for whom you want to create a Zulip dev droplet")

View File

@ -3,31 +3,32 @@
Fetch contributors data from Github using their API, convert it to structured
JSON data for the /team page contributors section.
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from scripts.lib.setup_path import setup_path
setup_path()
from typing import Any, Dict, List, Optional, Union
from typing_extensions import TypedDict
import argparse
from time import sleep
import logging
from datetime import date
from random import randrange
import logging
from time import sleep
from typing import Any, Dict, List, Optional, Union
from typing_extensions import TypedDict
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
import django
django.setup()
from django.conf import settings
import json
import requests
import json
from django.conf import settings
duplicate_commits_file = os.path.join(os.path.dirname(__file__), 'duplicate_commits.json')

View File

@ -5,7 +5,6 @@
from lib import sanity_check
sanity_check.check_venv(__file__)
import os
import sys
@ -26,23 +25,33 @@ import argparse
import base64
import subprocess
from typing import Any, Dict, Optional
from urllib.parse import urlencode, parse_qsl
from urllib.parse import parse_qsl, urlencode
import requests
import ujson
from scripts.lib.zulip_tools import BOLDRED, ENDC
from tools.lib.test_script import prepare_puppeteer_run
from zerver.models import UserProfile, Message, get_user_by_delivery_email, get_realm
from zerver.lib.actions import (
do_create_user, notify_created_bot, bulk_add_subscriptions, do_change_avatar_fields)
bulk_add_subscriptions,
do_change_avatar_fields,
do_create_user,
notify_created_bot,
)
from zerver.lib.integrations import (
DOC_SCREENSHOT_CONFIG,
INTEGRATIONS,
ScreenshotConfig,
WebhookIntegration,
get_fixture_and_image_paths,
split_fixture_path,
)
from zerver.lib.storage import static_path
from zerver.lib.streams import create_stream_if_needed
from zerver.lib.upload import upload_avatar_image
from zerver.lib.integrations import (
WebhookIntegration, INTEGRATIONS, split_fixture_path, ScreenshotConfig, get_fixture_and_image_paths,
DOC_SCREENSHOT_CONFIG)
from zerver.lib.webhooks.common import get_fixture_http_headers
from zerver.lib.storage import static_path
from zerver.models import Message, UserProfile, get_realm, get_user_by_delivery_email
def create_integration_bot(integration: WebhookIntegration, bot_name: Optional[str]=None) -> UserProfile:
realm = get_realm('zulip')

View File

@ -5,6 +5,7 @@ import re
from subprocess import check_output
from typing import Dict, List
def get_json_filename(locale: str) -> str:
return f"locale/{locale}/mobile.json"

View File

@ -1,8 +1,7 @@
#!/usr/bin/env python3
import configparser
from hashlib import md5
import os
from hashlib import md5
import polib

View File

@ -1,5 +1,5 @@
from typing import List, Tuple, Match
import re
from typing import List, Match, Tuple
from bs4 import BeautifulSoup

View File

@ -1,9 +1,9 @@
from typing import Text, List
import re
from typing import List, Text
from gitlint.git import GitCommit
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle
from gitlint.options import StrOption
import re
from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation
# Word list from https://github.com/m1foley/fit-commit
# Copyright (c) 2015 Mike Foley

View File

@ -1,13 +1,8 @@
from typing import Dict, List, Optional, Set
import re
from collections import defaultdict
from typing import Dict, List, Optional, Set
from .template_parser import (
tokenize,
FormattedException,
Token,
)
from .template_parser import FormattedException, Token, tokenize
class HtmlBranchesException(Exception):

View File

@ -1,13 +1,10 @@
import subprocess
from typing import Any, Dict, List
from .template_parser import (
tokenize,
is_django_block_tag,
)
from zulint.printer import ENDC, GREEN
from zulint.printer import GREEN, ENDC
from .template_parser import is_django_block_tag, tokenize
import subprocess
def pretty_print_html(html: str, num_spaces: int = 4) -> str:
# We use 1-based indexing for both rows and columns.

View File

@ -1,28 +1,37 @@
#!/usr/bin/env python3
import os
import sys
import logging
import argparse
import hashlib
import logging
import os
import platform
import subprocess
import hashlib
import sys
os.environ["PYTHONUNBUFFERED"] = "y"
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import run_as_root, ENDC, WARNING, \
get_dev_uuid_var_path, FAIL, os_families, parse_os_release, \
overwrite_symlink
from typing import TYPE_CHECKING, List
from scripts.lib.node_cache import NODE_MODULES_CACHE_PATH, setup_node_modules
from scripts.lib.setup_venv import (
get_venv_dependencies, THUMBOR_VENV_DEPENDENCIES,
THUMBOR_VENV_DEPENDENCIES,
YUM_THUMBOR_VENV_DEPENDENCIES,
get_venv_dependencies,
)
from scripts.lib.zulip_tools import (
ENDC,
FAIL,
WARNING,
get_dev_uuid_var_path,
os_families,
overwrite_symlink,
parse_os_release,
run_as_root,
)
from scripts.lib.node_cache import setup_node_modules, NODE_MODULES_CACHE_PATH
from tools.setup import setup_venvs
from typing import List, TYPE_CHECKING
if TYPE_CHECKING:
from typing import NoReturn

View File

@ -1,22 +1,26 @@
#!/usr/bin/env python3
import os
import sys
import argparse
import glob
import os
import shutil
import sys
from typing import List
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.append(ZULIP_PATH)
from scripts.lib.zulip_tools import run, OKBLUE, ENDC, \
get_dev_uuid_var_path, is_digest_obsolete, write_new_digest
from version import PROVISION_VERSION
from pygments import __version__ as pygments_version
from scripts.lib.zulip_tools import (
ENDC,
OKBLUE,
get_dev_uuid_var_path,
is_digest_obsolete,
run,
write_new_digest,
)
from tools.setup.generate_zulip_bots_static_files import generate_zulip_bots_static_files
from version import PROVISION_VERSION
VENV_PATH = "/srv/zulip-py3-venv"
UUID_VAR_PATH = get_dev_uuid_var_path()
@ -177,7 +181,7 @@ def clean_unused_caches() -> None:
verbose=False,
no_headings=True,
)
from scripts.lib import clean_venv_cache, clean_node_cache, clean_emoji_cache
from scripts.lib import clean_emoji_cache, clean_node_cache, clean_venv_cache
clean_venv_cache.main(args)
clean_node_cache.main(args)
clean_emoji_cache.main(args)
@ -227,12 +231,13 @@ def main(options: argparse.Namespace) -> int:
import django
django.setup()
from django.conf import settings
from zerver.lib.test_fixtures import (
DEV_DATABASE,
TEST_DATABASE,
destroy_leaked_test_databases,
)
from django.conf import settings
if options.is_force or need_to_run_configure_rabbitmq(
[settings.RABBITMQ_PASSWORD]):

View File

@ -2,6 +2,7 @@ import os
import pwd
import sys
def check_venv(filename: str) -> None:
try:
import django

View File

@ -1,5 +1,6 @@
from typing import Callable, List, Optional, Text
class FormattedException(Exception):
pass

View File

@ -1,12 +1,12 @@
from typing import Optional, Tuple, Iterable, List
import glob
import os
import subprocess
import sys
from distutils.version import LooseVersion
from version import PROVISION_VERSION
from typing import Iterable, List, Optional, Tuple
from scripts.lib.zulip_tools import get_dev_uuid_var_path
import glob
from version import PROVISION_VERSION
ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

View File

@ -2,13 +2,12 @@ import os
import subprocess
import sys
import time
from contextlib import contextmanager
from typing import Iterator, Optional
# Verify the Zulip venv is available.
from tools.lib import sanity_check
sanity_check.check_venv(__file__)
import django
@ -20,8 +19,9 @@ TOOLS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if TOOLS_DIR not in sys.path:
sys.path.insert(0, os.path.dirname(TOOLS_DIR))
from zerver.lib.test_fixtures import update_test_databases_if_required
from scripts.lib.zulip_tools import get_or_create_dev_uuid_var_path
from zerver.lib.test_fixtures import update_test_databases_if_required
def set_up_django(external_host: str) -> None:
os.environ['EXTERNAL_HOST'] = external_host

View File

@ -1,16 +1,20 @@
#!/usr/bin/env python3
import argparse
import os
import sys
import argparse
# check for the venv
from lib import sanity_check
sanity_check.check_venv(__file__)
from linter_lib.custom_check import python_rules, non_py_rules
from zulint.command import add_default_linter_arguments, LinterConfig
import random
from zulint.command import LinterConfig, add_default_linter_arguments
from linter_lib.custom_check import non_py_rules, python_rules
def run() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--force', default=False,
@ -26,13 +30,10 @@ def run() -> None:
root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir)
from tools.lib.test_script import assert_provisioning_status_ok
from tools.linter_lib.exclude import EXCLUDED_FILES, PUPPET_CHECK_RULES_TO_EXCLUDE
from tools.linter_lib.pyflakes import check_pyflakes
from tools.linter_lib.pep8 import check_pep8
from tools.lib.test_script import (
assert_provisioning_status_ok,
)
from tools.linter_lib.pyflakes import check_pyflakes
os.chdir(root_dir)

View File

@ -1,6 +1,7 @@
from typing import List
from zulint.linters import run_pycodestyle
from typing import List
def check_pep8(files: List[str]) -> bool:
ignored_rules = [

View File

@ -1,5 +1,4 @@
import argparse
from typing import List
from zulint.linters import run_pyflakes

View File

@ -1,7 +1,9 @@
#!/usr/bin/env python3
from typing import List
from lib.pretty_print import pretty_print_html
import sys
from typing import List
from lib.pretty_print import pretty_print_html
def clean_html(filenames: List[str]) -> None:
for fn in filenames:

View File

@ -1,13 +1,12 @@
#!/usr/bin/env python3
import fileinput
import glob
import os
import sys
import fileinput
import re
import sys
from typing import List
def validate_order(order: List[int], length: int) -> None:
if len(order) != length:
print("Please enter the sequence of all the conflicting files at once")

View File

@ -1,10 +1,10 @@
#!/usr/bin/env python3
import shlex
import subprocess
import sys
from typing import List
def exit(message: str) -> None:
print('PROBLEM!')
print(message)

Some files were not shown because too many files have changed in this diff Show More