Skip to content

Commit

Permalink
Merge pull request #36 from chriskuehl/no_timestamp
Browse files Browse the repository at this point in the history
Add option to disable generate timestamps
  • Loading branch information
asottile committed Jun 10, 2018
2 parents 1399559 + 6a8c600 commit a66862a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
12 changes: 12 additions & 0 deletions dumb_pypi/main.py
Expand Up @@ -206,6 +206,7 @@ class Settings(NamedTuple):
title: str
logo: str
logo_width: int
generate_timestamp: bool


def build_repo(packages: Dict[str, Set[Package]], settings: Settings) -> None:
Expand Down Expand Up @@ -235,6 +236,7 @@ def build_repo(packages: Dict[str, Set[Package]], settings: Settings) -> None:
with atomic_write(os.path.join(simple, 'index.html')) as f:
f.write(jinja_env.get_template('simple.html').render(
date=current_date,
generate_timestamp=settings.generate_timestamp,
package_names=sorted(packages),
))

Expand All @@ -250,6 +252,7 @@ def build_repo(packages: Dict[str, Set[Package]], settings: Settings) -> None:
with atomic_write(os.path.join(simple_package_dir, 'index.html')) as f:
f.write(jinja_env.get_template('package.html').render(
date=current_date,
generate_timestamp=settings.generate_timestamp,
package_name=package_name,
files=sorted_files,
packages_url=settings.packages_url,
Expand Down Expand Up @@ -327,6 +330,14 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
'--logo-width', type=int,
help='width of logo to display', default=0,
)
parser.add_argument(
'--no-generate-timestamp',
action='store_false', dest='generate_timestamp',
help=(
"Don't template creation timestamp in outputs. This option makes "
'the output repeatable.'
),
)
args = parser.parse_args(argv)

settings = Settings(
Expand All @@ -335,6 +346,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
title=args.title,
logo=args.logo,
logo_width=args.logo_width,
generate_timestamp=args.generate_timestamp,
)
build_repo(args.packages, settings)
return 0
Expand Down
4 changes: 3 additions & 1 deletion dumb_pypi/templates/package.html
Expand Up @@ -6,7 +6,9 @@
<body>
<h1>{{package_name}}</h1>
<p>Latest version: {{(files|first).version}}</p>
<p>Generated on {{date}}.</p>
{% if generate_timestamp %}
<p>Generated on {{date}}.</p>
{% endif %}
<ul>
{% for file in files %}
<li><a href="{{file.url(packages_url)}}">{{file.filename}}</a> ({{file.info_string}})</li>
Expand Down
4 changes: 3 additions & 1 deletion dumb_pypi/templates/simple.html
Expand Up @@ -5,7 +5,9 @@
</head>
<body>
<h1>Simple index</h1>
<p>Generated on {{date}}.</p>
{% if generate_timestamp %}
<p>Generated on {{date}}.</p>
{% endif %}
<ul>
{% for package in package_names %}
<li><a href="{{package}}/">{{package}}</a></li>
Expand Down
13 changes: 13 additions & 0 deletions tests/main_test.py
Expand Up @@ -199,6 +199,19 @@ def test_build_repo_json_smoke_test(tmpdir):
assert tmpdir.join('simple', 'ocflib', 'index.html').check(file=True)


def test_build_repo_no_generate_timestamp(tmpdir):
package_list = tmpdir.join('package-list')
package_list.write('pkg-1.0.tar.gz\n')
main.main((
'--package-list', package_list.strpath,
'--output-dir', tmpdir.strpath,
'--packages-url', '../../pool',
'--no-generate-timestamp',
))
for p in ('simple/index.html', 'simple/pkg/index.html'):
assert 'Generated on' not in tmpdir.join(p).read()


def test_build_repo_even_with_bad_package_names(tmpdir):
package_list = tmpdir.join('package-list')
package_list.write('\n'.join((
Expand Down

0 comments on commit a66862a

Please sign in to comment.